Null Response To cPanel API Calls From Silex Closure [resolved]

MattDr2

Well-Known Member
PartnerNOC
Feb 19, 2003
84
0
156
Norman, OK
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:
Code:
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.

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');
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).

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();
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.
 
Last edited:

MattDr2

Well-Known Member
PartnerNOC
Feb 19, 2003
84
0
156
Norman, OK
It looks like the issue is that the CPANEL class is being destructed (__destruct()) before closures are called, which is causing this problem.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

I'm happy to see the issue is now resolved. Thank you for updating us with the outcome.