blackfireio / php-sdk

The Blackfire PHP SDK
https://blackfire.io
MIT License
150 stars 22 forks source link

"Another probe is already profiling" with LoopClient #30

Open maxgalbu opened 6 years ago

maxgalbu commented 6 years ago

test.php is the same code as the php sdk guide:

$ cat test.php 
<?php
require_once __DIR__.'/vendor/autoload.php';

use Blackfire\LoopClient;
use Blackfire\Client;
use Blackfire\Profile\Configuration as ProfileConfiguration;

function consume()
{
echo "Message consumed!\n";
}

$blackfire = new LoopClient(new Client(), 10);
$profileConfig = new ProfileConfiguration();
$profileConfig->setTitle('Consumer');

for (;;) {
$blackfire->startLoop($profileConfig);

consume();

if ($profile = $blackfire->endLoop()) {
print $profile->getUrl()."\n";
}

usleep(400000);
}

This is the output:

$ blackfire run php test.php
PHP Fatal error:  Uncaught exception 'Blackfire\Exception\ApiException' with message '101: An other probe is already profiling' in /var/www/hs-pv4/vendor/blackfire/php-sdk/src/Blackfire/Exception/ApiException.php:18
Stack trace:
#0 /var/www/hs-pv4/vendor/blackfire/php-sdk/src/Blackfire/Probe.php(85): Blackfire\Exception\ApiException::fromStatusCode('An other probe ...', '101')
#1 /var/www/hs-pv4/vendor/blackfire/php-sdk/src/Blackfire/Probe.php(58): Blackfire\Probe->checkError()
#2 /var/www/hs-pv4/vendor/blackfire/php-sdk/src/Blackfire/LoopClient.php(123): Blackfire\Probe->enable()
#3 /var/www/hs-pv4/test.php(18): Blackfire\LoopClient->startLoop(Object(Blackfire\Profile\Configuration))
#4 {main}
  thrown in /var/www/hs-pv4/vendor/blackfire/php-sdk/src/Blackfire/Exception/ApiException.php on line 18
Error while running command: exit status 255

Blackfire Run completed
Graph URL https://blackfire.io/profiles/7d0c5874-547a-4a2f-ae32-ef67ab604671/graph
No tests! Create some now https://blackfire.io/docs/cookbooks/tests
No recommendations

PHP version:

$ php -v
PHP 5.6.16 (cli) (built: Dec 18 2015 10:40:37) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with blackfire v1.18.1~linux-x64-zts56, https://blackfire.io, by SensioLabs
maxgalbu commented 6 years ago

Apparently blackfire starts a probe as soon as the script starts. To stop it:

$probe = \BlackfireProbe::getMainInstance();
$probe->discard();

Even if I do this, after doing endLoop() nothing shows up on the blackfire.io dashboard.