Null Response To cPanel API Calls From Silex Closure [resolved]
I'm developing a cPanel plugin using Silex. Silex runs a lot of code inside closures, and I'm having difficulty using the cPanel API (/usr/local/cpanel/php/cpanel.php) from within a closure.
In the global context, cPanel API queries return properly, no issues there. This is working fine:
But, if I remove the above code and instead try to activate the CPANEL class via a closure, like below, I receive null responses to all requests. I don't receive any exceptions, only null responses to requests. In reviewing the cpanel.php code, I would expect exceptions rather than null responses.
Further, if I try to activate the class and use it within its own closure, the issue is the same. I also can't use a globally activated CPANEL class from within a closure (below).
Is this expected behavior that the cPanel PHP socket cannot be accessed inside a closure? I've scoured the net but can't find any indication that sockets in general shouldn't be accessible in this way, and I can't see any reason this would be restricted when looking through the code in the cpanel.php file. If anything, I should get some kind of exception returned. Edit: I should also add that this occurs inside any PHP closure regardless of the use of Silex functions as a wrapper. Any help would be much appreciated.
include("/usr/local/cpanel/php/cpanel.php");
$cpanel = new CPANEL();
$domains = $cpanel->uapi('DomainInfo', 'list_domains');
//...
$cpanel->end();
But, if I remove the above code and instead try to activate the CPANEL class via a closure, like below, I receive null responses to all requests. I don't receive any exceptions, only null responses to requests. In reviewing the cpanel.php code, I would expect exceptions rather than null responses.
$app['cpanel"> = $app->share(function () {
include("/usr/local/cpanel/php/cpanel.php");
return new CPANEL();
});
// Returns NULL
$domains = $app['cpanel">->uapi('DomainInfo', 'list_domains');
Further, if I try to activate the class and use it within its own closure, the issue is the same. I also can't use a globally activated CPANEL class from within a closure (below).
include("/usr/local/cpanel/php/cpanel.php");
$cpanel = new CPANEL();
$app->get('/test/{domain}', function ($domain, Application $app) use ($cpanel) {
// Returns NULL
$mxList= $cpanel->uapi('Email', 'list_mxs');
});
// Returns valid data
$mxList= $cpanel->uapi('Email', 'list_mxs');
//...
$cpanel->end();
Is this expected behavior that the cPanel PHP socket cannot be accessed inside a closure? I've scoured the net but can't find any indication that sockets in general shouldn't be accessible in this way, and I can't see any reason this would be restricted when looking through the code in the cpanel.php file. If anything, I should get some kind of exception returned. Edit: I should also add that this occurs inside any PHP closure regardless of the use of Silex functions as a wrapper. Any help would be much appreciated.
-
It looks like the issue is that the CPANEL class is being destructed (__destruct()) before closures are called, which is causing this problem. 0 -
Got it - it's my fault. :) I was running $cpanel->end() before running the Silex application. 0 -
Hello :) I'm happy to see the issue is now resolved. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
3 comments