Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    3

    Default php cron job with url parameters

    Hi There,

    I have read through the forum and have not been able to see this problem described anywhere.

    I am trying to execute a php scrip through cron and can successfully do so with the following line:

    php /home/MyPath/public_html/cron.php

    The problem is that I need to append some parameters to the php scrip like this:

    php /home/MyPath/public_html/cron.php?paremeter1=value1&patermeter2=value2

    This does not work. I think the error was "File not found". Which is sort of obvious in retrospect since it is a file path based execution.

    I then changed the cron to execute a different php file:

    php /home/MyPath/public_html/cron_redirect.php

    In this file I have the following code:

    Code:
    <?php
    header("Location: http://www.mysite.com/cron.php?paremeter1=value1&patermeter2=value2");
    ?>
    This does not work. I get an email from cron saying:

    Status: 302
    X-Powered-By: PHP/4.4.1
    Location: http://www.mysite.com/cron.php?parem...rmeter2=value2
    Content-type: text/html

    But my file is not redirected.

    Can someone help me please?

    Thanks a bunch!

  2. #2
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Default

    If you execute your PHP script via CRON, it is running as CLI (Command Line Interface)
    which has a lot of different rules than the normal Web based PHP interface.

    Parameters are read as number command line parameters of any other shell script language
    which means you need to add spaces to the request between each parameter and use PHP's
    added commands for CLI use for reading those parameters.

    See the PHP site at http://www.php.net for more information about using CLI based PHP.

  3. #3
    Member
    Join Date
    Jan 2005
    Posts
    1,880

    Default

    Try setting the cron task as

    Code:
    /usr/bin/lynx http://www.example.com/script.php?parameter1=value1&parameter2=value2
    This sort of thing works fine for me.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    3

    Default

    Hi There,

    I could get the Lynx option to work. It came back with:

    Your Terminal type is unknown!

    Enter a terminal type: [vt100]
    TERMINAL TYPE IS SET TO vt100
    (B)0[?7h[?1h=Getting http://www.mysite.com/index.php?option=option
    Looking up www.mysite.com 
    Making HTTP connection to www.mysite.com
    Sending HTTP request. 
    HTTP request sent; waiting for response.

    
    [?1l>

    But the script does not execute.

    The script takes a long time to execute since I am throtteling several emails being sent each with a 10 seccond interval between them. Could this be the reason?

    It works when I open the page manually in IE.

    Thank you,

    Soren

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    3

    Default

    Hey!

    Got tit to work by parsing the arguments to the file like this:

    php /home/public_html/mysite/index.php var1=value1 var2=value2

    Just in case someone has the same problem!

    Thank you for the help!

Similar Threads & Tags
Similar threads

  1. Need Help with my Cron Job Script [moved]
    By psquillace in forum Data Protection
    Replies: 5
    Last Post: 08-22-2006, 12:32 PM
  2. cron job, help [moved]
    By tabuladze in forum New User Questions
    Replies: 4
    Last Post: 06-15-2006, 08:03 PM
  3. Problems php file - cron job [moved]
    By bogdanovici666 in forum New User Questions
    Replies: 2
    Last Post: 05-19-2006, 09:37 AM
  4. Daily Cron job [moved]
    By Justin182004 in forum Data Protection
    Replies: 1
    Last Post: 09-24-2005, 05:14 PM
  5. Cron job help? [moved]
    By Katrina M. in forum New User Questions
    Replies: 2
    Last Post: 09-09-2005, 07:30 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube