Standardized Hook to call API1 functions - how to debug?


Nov 11, 2013
cPanel Access Level
Root Administrator
I'm developing a hook but can't seem to get API1 calls working

The hook has been registered via manage_hook and runs (I've enabled debughooks (level 3) and checked the error_log - the correct hook is being called and the correct data is being sent)

However, there aren't many docs on how to do anything from within the hook. I'm attempting to use XML-API1 (with xmlapi.php included) - see below:

function hook() {
    $stdin_fh = fopen('php://stdin', 'r');
    while ($line = fgets( $stdin_fh )) {
        $raw_data .= $line;
    $hookdata = json_decode($raw_data, true);

    $context = $hookdata['context'];
    $data = $hookdata['data'];
    if($data['plan'] == "Joomla"){
        // Connect to API1
        $ip = ""; 
        $root_pass = "XXXXXXXX"; 
        $xmlapi = new xmlapi($ip); 
        $xmlapi->password_auth("root", $root_pass); 

        // Create the database
        $account = $data['user'];
        $database = $data['user']."_joomla";
        print $xmlapi->api1_query($account, "Mysql", "adddb", array($database)); 
        // Create the database user
        $dbUsername = $data['user']."_sys";
        $dbPassword = $data['pass'];
        echo $xmlapi->api1_query($account, "Mysql", "adduser", array($dbUsername, dbPassword));
        // Give new user permissions for new db
        $dbPermissions = "all";
        echo $xmlapi->api1_query($account, "Mysql", "adduserdb", array($database, $dbUsername, $dbPermissions));
        // Export Joomla from SVN
        //shell_exec("svn export /home/".$data['user']."/public_html/ --force");
        //shell_exec("chown -R ".$data['user'].":".$data['user']." /home/".$data['user']."/public_html/*");
        return 1, "Created ".$database." DB, created ".$dbUsername." user (password '".$dbPassword."')";
    return 1, "Joomla plan not selected";
How can I:

a) Output data from the hook function so I can debug? (i.e. where does $xmlapi sent its output to? Where do hook 'prints' go to?
b) Get the API calls to work?

Many thanks!



Well-Known Member
Verifed Vendor
Jun 17, 2010
San Francisco, CA
cPanel Access Level
Root Administrator
You can print output to /usr/local/cpanel/logs/error_log with error_log(), or you can print to another file of your choice. In the hook system, it's really just a wrapper that executes your script via the command line so you won't see any output from print/echo. Since it's just like executing your script via the command line with some data passed in by cPanel, I'd first recommend getting things working from the command line without the cPanel params and then altering the script to use the data from STDIN.

I don't see anything wrong with the xmlapi code but if there is, you'll be able to capture the errors when testing via the command line as they'll either print to STDOUT or /usr/local/cpanel/logs/error_log.