Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Standardized Hook to call API1 functions - how to debug?

Discussion in 'cPanel Developers' started by muckypuddle, Nov 11, 2013.

  1. muckypuddle

    muckypuddle Registered

    Nov 11, 2013
    Likes Received:
    Trophy Points:
    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_datatrue);

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

    // Create the database
    $account $data['user'];
    $database $data['user']."_joomla";
    $xmlapi->api1_query($account"Mysql""adddb", array($database)); 
    // Create the database user
    $dbUsername $data['user']."_sys";
    $dbPassword $data['pass'];
    $xmlapi->api1_query($account"Mysql""adduser", array($dbUsernamedbPassword));
    // Give new user permissions for new db
    $dbPermissions "all";
    $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."')";
    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!

  2. KostonConsulting

    KostonConsulting Well-Known Member

    Jun 17, 2010
    Likes Received:
    Trophy Points:
    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.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice