www.webdeveloper.com
Results 1 to 5 of 5

Thread: GoDaddy Cron job http api call - really dumb question

  1. #1
    Join Date
    Mar 2013
    Posts
    3

    Unhappy GoDaddy Cron job http api call - really dumb question

    OK I haven't programmed (apart from HTML - is that really programming???) for over 20 year.

    Trying to get back up to speed. Getting just about there in JS but want to use CRON to launch a process at GoDaddy.

    I have an account with Clickatell. They send SMSs by a v simple HTTP call eg

    http://clickatell.com/api/123/passwo...4568&msg=hello dolly


    All I want to be able to do is launch that http call from within a php page for now and I am damned if I can see how to do it. (It cab be php, perl, ruby,bash or a couple of other languages)


    (BTW I also realised in my test set up I was using JS and I presume that JS will NOT work if it is essentially running on GoDaddys servers. That is a side question.)

    Sorry for the hugely dumb questions.

    I have spent literllaly hours looking for this and the answer may be buried here but I cannot see it.

    Thanks in advance for any gentle help.
    Aloha Steve

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    Probably the most common way to do this within a PHP script is to use the cURL functions. It can get a bit fiddly at times if you have to mess around with a bunch of "setopt" parameters, but if you're lucky, it might be as simple as something like:
    PHP Code:
    $url "http://clickatell.com/api/123?password=".urlencode($password)."&telephone-no=".urlencode($telephone)."&msg=".urlencode($message);
    $curl curl_init($url);
    curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
    $result curl_exec($curl);
    // do stuff with $result.... 
    That was typed from memory, so may be wrong, incomplete, etc....
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2013
    Posts
    3
    NogDog well the system just ate my reply so here goes again.

    First thanks for your prompt reply but I think this is NOT quite what I am trying to do.

    I am not trying to edit the api call AT ALL at this stage I am just trying to do a call and get a text sent - I can build from there.

    For starters I can use JS or whatever to rewrite the file that the CRON job fires off.

    As for cURL, is that part of the base release of PHP 5.3? I saw somewhere I had to edit my php.ini file to get it working but there is no mention of cURL in the ini file. Anyway that really is a question for another day.

    Oh I remember the second part of my previously eaten question. I am assuming that any Javascript in a PHP page read as the CRON script on a GoDaddy server will be ignored. Am I right in that I assume that? Just helps in the controls I can use on the page.

    Once again pls forgive my ignorance and thanks for the pointer.

    Aloha Steve

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    The point is that cURL is used to send HTTP requests directly from within your executing PHP script to whatever URL you want, which is typically what you want to do when accessing an API. I was just giving an example of how you might dynamically build a URL string (being sure to url-encode things that might have to be encoded) in order to create the URL to be transmitted. Normally you don't want to send the exact same request data every time -- usually there is something dynamic going on -- if not, then just ignore that part.

    As to whether or not cURL is enabled in your installation, I have no way to know. I suppose you could just try a simple script that tries to do a curl_init(), and see if it blows up or not. If it is, in fact, not enabled/installed, then the options are to get it installed, find out if the url_fopen option is enabled (usually not due to security issues) and just put the url into a file_get_contents() call, or switch to another host.

    Or the other alternative is that I'm totally misunderstanding the situation and what you want to do.

    As for JavaScript that is output by a PHP script: yes, it only gets run by the client (typically a web browser) when it receives the output from your PHP script.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Mar 2013
    Posts
    3
    Quote Originally Posted by NogDog View Post
    The point is that cURL is used to send HTTP requests directly from within your executing PHP script to whatever URL you want, which is typically what you want to do when accessing an API. I was just giving an example of how you might dynamically build a URL string (being sure to url-encode things that might have to be encoded) in order to create the URL to be transmitted. Normally you don't want to send the exact same request data every time -- usually there is something dynamic going on -- if not, then just ignore that part.

    As to whether or not cURL is enabled in your installation, I have no way to know. I suppose you could just try a simple script that tries to do a curl_init(), and see if it blows up or not. If it is, in fact, not enabled/installed, then the options are to get it installed, find out if the url_fopen option is enabled (usually not due to security issues) and just put the url into a file_get_contents() call, or switch to another host.

    Or the other alternative is that I'm totally misunderstanding the situation and what you want to do.

    As for JavaScript that is output by a PHP script: yes, it only gets run by the client (typically a web browser) when it receives the output from your PHP script.
    You, sire, are a gentleman (or lady!!!!)

    I hacked the code a bit went away and more by chance came up with:

    PHP Code:
    <?php 
     $url 
    'http://api.clickatell.com/http/sendmsg?user=fffffffffff&password=xxxxxxx&api_id=xxxxxx&from=999999999&mo=1&to=99999999&text=Rebecca%20CRON%20loves%20you!';
     
       
        
    $ch curl_init($url);
        
    curl_exec($ch);
        
    curl_close($ch);

        echo 
    $result;
        
        

    ?>
    I cannot tell a lie I am not really sure what I am doing but it worked.

    Now I have to try and get my head around php and MySQL and Javascript to bring it all together :-(

    Thanks for the pointer.

    Aloha Steve

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles