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.

livephp api call from domain

Discussion in 'cPanel Developers' started by coombesy, Feb 7, 2012.

  1. coombesy

    coombesy Registered

    Joined:
    Feb 7, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hi,

    I'm trying to set up a secure app that will create emails for me, but I'm having issues at every corner. What I have at the moment is php script in:
    /home/website/public_html/cpanel_request.php
    PHP:
    <?php
    include "/usr/local/cpanel/base/frontend/x3/WebSite.livephp";
    WebSite.live.php:
    PHP:
    <?php
    require_once "/usr/local/cpanel/php/cpanel.php";
    $cpanel = new CPANEL();
    print_r($cpanel);
    ?>
    when I run cpanel_request.php in the browser I get:
    Code:
    Warning:  fsockopen() [function.fsockopen]: unable to connect to unix://:-1 (Invalid argument) in /home/website/public_html/cpanel_r on line 12
    
    Fatal error:  Uncaught exception 'Exception' with message 'There was a problem connecting back to the cPanel engine.  Make sure your script ends with .live.php or .livephp'
    
    The error is being thrown in CPANEL::__constructor in /usr/local/cpanel/php/cpanel.php because the environment variable CPANEL_PHPCONNECT_SOCKET is empty. Here is a snippet of code from that class thats throwing the excpetion:
    PHP:
            $socketfile getenv('CPANEL_PHPCONNECT_SOCKET');
            
    $this->_cpanelfh fsockopen("unix://" $socketfile);
            if (!
    $this->_cpanelfh) {
                
    $this->connected 0;
                throw new 
    Exception("There was a problem connecting back to the cPanel engine.  Make sure your script ends with .live.php or .livephp");
            }
            
    stream_set_blocking($this->_cpanelfh1) || $this->connected 0;
            if (!
    $this->connected) {
                throw new 
    Exception("There was a problem connecting back to the cPanel engine.  Make sure your script ends with .live.php or .livephp");
            }
    My ultimate aim is to have email accounts created when a user signs up on my site. My reason for choosing this method over http calls was for security, but then I'm reading that livephp is only for creating plugins.

    Lost, any direction would be helpful,
    coombesy
     
  2. charsleysa

    charsleysa Active Member

    Joined:
    Jul 18, 2011
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Palmerston North, New Zealand
    cPanel Access Level:
    Root Administrator
    The problem is that LivePHP cannot be used from a website sorry.
    You must revert to using the standard XML-API class, it is really useful in JSON mode, although it needs to be updated so it can use PHP's json_decode function as it currently returns raw JSON.
     
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Just to add a touch to charsleysa's answer:

    The cPanel LiveAPI (.live.php, .livephp, .live.pl, etc) must be run within the cPanel web server (cpsrvd). That means that your code must exist in one of the following cPanel document roots:

    /usr/local/cpanel/base/frontend/
    /usr/local/cpanel/base/3rdparty/

    Anything outside of the cPanel web server requires you to use another method to connect (XML-API in JSON/XML, Cpanel::PublicAPI, Cpanel::XML).
     
Loading...

Share This Page