krakjoe / tombs

Detect unused code in production
Other
433 stars 20 forks source link

Tombs returns empty results #14

Closed efeferrari closed 3 years ago

efeferrari commented 3 years ago

Hi @krakjoe. I follow all the steps for install Tombs. When I run php -v returns the expected: with Tombs v0.0.3-dev, Copyright (c) 2020, by krakjoe

This is my tombs.ini

; Tombs
zend_extension=/usr/lib/php/20170718/tombs.so
tombs.slots=9000000
tombs.strings=32M
tombs.socket=unix://zend.tombs.socket
tombs.dump=0
tombs.namespace=/path/to/source/files/
tombs.graveyard_format=json

Then I run my application, do a lot of requests with API and using the Backend, but when I run this script, It's always empty

$host = ini_get('tombs.socket');
$data = get_tombs_data($host);

var_dump($data);

function get_tombs_data(string $host)
{
    $socket = fsockopen($host);

    if (!$socket) {
        throw new \RuntimeException('cannot open ' . $host);
    }

    return stream_get_contents($socket);
}

Result:

string(0) ""

I'm using PHP 7.2 in unix environment. It's there some error with the configs or the retrieving data method? I even created a dummy function called neverCallMe() and doesn't appears on Tombs report

Tomb tests

Also, I tried to run the original test "004.phpt" like this:

class Foo {
    public function bar() {}
    public function qux() {}
}

$foo = new foo();
$foo->qux();

zend_tombs_display(ini_get('tombs.socket'));

function zend_tombs_display(string $ip) {
    $socket = fsockopen($ip);

    if (!$socket) {
        throw new \RuntimeException("cannot open {$ip}");
    }

    echo stream_get_contents($socket);
}

But always get an empty result

krakjoe commented 3 years ago

tombs.namespace is not a path, it's a namespace.

efeferrari commented 3 years ago

are you 100% sure that's my mistake?

rakeev commented 2 years ago

same, it just does not work even without namespace

Wojciechem commented 11 months ago

For anyone else from "the future" that stumbles upon this.

  1. Please make sure that php-fpm does indeed load the tombs config.
  2. With the following configuration:
    zend_extension  = tombs.so
    tombs.slots     = 10000000
    tombs.strings   = 32M
    tombs.socket    = /tmp/zend.tombs.socket
    tombs.dump      = /tmp/zend.tombs.dump

I've noticed that /tmp/zend.tombs.socket exists only as long as the php process is running. When I'm trying to collect data from php-fpm, and in the meantime run any php cli script, then the socket/file is removed.

Try: