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.

php cron job with url parameters [moved]

Discussion in 'General Discussion' started by CT Internet, Feb 24, 2006.

  1. CT Internet

    CT Internet Registered

    Joined:
    Feb 24, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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?paremeter1=value1&patermeter2=value2
    Content-type: text/html

    But my file is not redirected.

    Can someone help me please?

    Thanks a bunch!
     
  2. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    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. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    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. CT Internet

    CT Internet Registered

    Joined:
    Feb 24, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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. CT Internet

    CT Internet Registered

    Joined:
    Feb 24, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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!
     
Loading...

Share This Page