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.

Cron Job with XML API 2 Please help

Discussion in 'cPanel Developers' started by derhanvx, May 18, 2011.

  1. derhanvx

    derhanvx Registered

    Joined:
    May 18, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Hello.

    Please check what errors in my code:

    PHP:
    <?php

    require_once('xmlapi.php'); 

    $ip 'www.mydomain.com';
    $account 'cp_user';
    $pass 'cp_password';

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account,$pass);
    $xmlapi->set_port('2083');
    $xmlapi->set_output("json");

    $command 'wget -q -O /dev/null "http://'.$ip.'/cron-job.php"';
    $args = array ( 'command' => '*/15',
                    
    'day' => '*',
                    
    'hour' => '*',
                    
    'minute' => '*',
                    
    'month' => '*',
                    
    'weekday' => '*',
                    );

    $xmlapi->set_debug(1);
    print 
    $xmlapi->api2_query($account'Cron','add_line'$args);


    ?>
    When i'm trying to run it i got this error:

    HTML:
    Fatal error: Uncaught exception 'Exception' with message 'curl_exec threw error "couldn't connect to host" for https://www.mydomain.com:2083/json-api/cpanel?command=%2A%2F15&day=%2A&hour=%2A&minute=%2A&month=%2A&weekday=%2A&cpanel_jsonapi_user=woutdlq&cpanel_jsonapi_module=Cron&cpanel_jsonapi_func=add_line&cpanel_jsonapi_apiversion=2' in /home/domain/public_html/xmlapi/xmlapi.php:721 Stack trace: #0 /home/domain/public_html/xmlapi/xmlapi.php(643): xmlapi->curl_query('https://www.myd...', 'command=%2A%2F1...', 'Authorization: ...') #1 /home/domain/public_html/xmlapi/xmlapi.php(866): xmlapi->xmlapi_query('cpanel', Array) #2 /home/domain/public_html/xmlapi/test.php(24): xmlapi->api2_query('cp_user', 'Cron', 'add_line', Array) #3 {main} thrown in /home/domain/public_html/xmlapi/xmlapi.php on line 721
    And i got this error when use $xmlapi->set_http_client('fopen'); :

    HTML:
    Warning: file_get_contents(https://www.mydomain.com:2083/json-api/cpanel) [function.file-get-contents]: failed to open stream: Connection refused in /home/domain/public_html/xmlapi/xmlapi.php on line 743
    Please help me to fix it.

    thanks in advance.
     
  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
    Hi derhanvx,

    Have you been able to make other calls successfully? Something simple like API2 StatsBar::Stats?

    Most of the time, errors like that are related to SSL. You'll want to check that you have SSL compiled in your PHP binary. The fopen stream wrappers need the OpenSSL extension; cURL would need to be the CurlSSL extension. Probably the quickest way to verify what you have is to make a page that renders phpinfo() and see what exactly is in the PHP binary that Apache is utilizing (FYI, it's possible that Apache will use a different PHP binary than /usr/bin/php [often the first in you bash path], so make sure to render phpinfo() in the same manner that you example script is being run [which I assume is a world facing web page due to the location of xmlapi.php]).

    If that is not the case, let me know and we can dig further.

    Regards,
    -DavidN
     
  3. derhanvx

    derhanvx Registered

    Joined:
    May 18, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    No, i also get the same error for API2 StatsBar::Stats.

    I already change the port to 2082, but it also generate the same error.

    Code:
    Warning: file_get_contents(http://www.mydomain.com:2082/json-api/cpanel) [function.file-get-contents]: failed to open stream: Connection refused in /home/domain/public_html/xmlapi/xmlapi.php on line 743

    i already render the phpinfo() and got this one:
    Code:
    Configuration File (php.ini) Path 	/usr/lib
    Loaded Configuration File 	/usr/local/lib/php.ini
    
    _SERVER["PATH"]	/bin:/usr/bin
    
    is this causing the problem?


    Here i am trying to connect to my cPanel to create a new cron job.
    but i always get stuck with this error.

    i wonder what is the main problem for "failed to open stream: Connection refused " in fopen connection method?

    thanks.
     
    #3 derhanvx, May 19, 2011
    Last edited: May 19, 2011
  4. 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
    I agree that the you're script is likely never reaching the destination. Have you tried using the IP of your server instead of the fully qualified domain name? If you are executing this script on the same server that you domain is hosted on, you can also use the loopback IP (127.0.0.1).

    re: phpinfo
    - you should have gotten a lot more info than that. The information that you posted has little to do with what SSL libraries you PHP binary is compiled with.

    Regards,
    -DavidN
     
Loading...
Similar Threads - Cron Job XML
  1. mesut85u2
    Replies:
    14
    Views:
    1,319

Share This Page