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.
In the global context, cPanel API queries return properly, no issues there. This is working fine:
Code:
include("/usr/local/cpanel/php/cpanel.php");
$cpanel = new CPANEL();
$domains = $cpanel->uapi('DomainInfo', 'list_domains');
//...
$cpanel->end();
Code:
$app['cpanel'] = $app->share(function () {
include("/usr/local/cpanel/php/cpanel.php");
return new CPANEL();
});
// Returns NULL
$domains = $app['cpanel']->uapi('DomainInfo', 'list_domains');
Code:
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();
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.
Last edited: