The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cpanel Hooks: Error accessing data with PHP

Discussion in 'cPanel Developers' started by failvalue, Apr 26, 2012.

  1. failvalue

    failvalue Registered

    Joined:
    Sep 7, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello,

    I am testing out a small plugin whereby I just print the cpanel user to the screen.

    I have saved the code below as /usr/local/cpanel/base/frontend/x3/test.live.php

    PHP:
    <?php
            $opts 
    = array();
            
    $argv0 array_shift($argv);
            while(
    count($argv)) {
                    
    $key array_shift($argv);
                    
    $value array_shift($argv);
                    
    $opts[$key] = $value;
            }
           
    $user $opts['user'];
           echo 
    $user;
    ?>
    When I run this by going to https://12.34.56.78:2083/frontend/x3/MyApp/test2.live.php in my browser I get the error:

    Warning: array_shift() expects parameter 1 to be array, null given in /usr/local/cpanel/base/frontend/x3/MyApp/test.live.php on line 3

    I have seen this exact code being referenced on numerous forum posts and it seems to work fine for everyone else. Can anyone point out to me where I am going wrong?

    I have included the entries from the cpanel error logs below.

    Regards,
    Colin

    # tail -f /usr/local/cpanel/logs/error_logs
    PHP Warning: array_shift() expects parameter 1 to be array, null given in /usr/local/cpanel/base/frontend/x3/MyApp/test2.live.php on line 3
    [2012-04-26 10:20:33 +0100] die [Internal Death while parsing [live php] 14202] Timed out waiting for live api connection. at cpanel line 4903.
    main::__ANON__('ALRM') called at cpanel line 4906
    main::setup_external_engine() called at cpanel line 389


    Timed out waiting for live api connection. at cpanel line 4903.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Like the error says, $argv is "null"...which means that $argv wasn't set. As stated in PHP manual about $argv, this variable only has meaning for command line usage (aka CLI SAPI). *.live.php will almost certainly be processed by a CGI SAPI when fired from a browser...and there's a fair chance that if you manual attempt to run your *live.php script like 'php test2.live.php' (that is `php` cmd without an absolute path), you might get CGI SAPI as well. This applies the same for CLI scripts trigger by cPanel (various hook systems or otherwise).

    I'm confused that the title of this thread is about cPanel Hooks, yet you're problem is related to LiveAPI...are you trying to execute a LiveAPI page as a hook? That likely won't work the way you think. In fact, from your error output above, it seems rather clear that the context you're calling from is not correct for LiveAPI to function properly. However, if you can provide more detail about what exactly you're doing it might clarify your needs; a more optional solution might present itself.

    Regards,
    -DavidN
     
Loading...

Share This Page