Results 1 to 6 of 6

Thread: Run a php file using URL in crontab?

  1. #1
    Join Date
    Feb 2013
    Beans
    2

    Run a php file using URL in crontab?

    I want to run a php file from a url using cron tab.
    I am using a webhosting and i give a command like that
    9 11 9 2 * wget -O /dev/null http://www.domainname.com/cronfile.php
    but it does not work please tell me why this not work.
    I think this command must run a "cronfile.php" and i do not want to recive any email from cron.
    Last edited by sandyd; February 10th, 2013 at 09:51 PM. Reason: removed edit button

  2. #2
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,093
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: Run a php file using URL in crontab?

    have you verified there are no errors in your php script?

    that is set to run on the 9th minute of 11th hour of the 9th day of the 2ed month
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  3. #3
    Join Date
    Feb 2013
    Beans
    2

    Re: Run a php file using URL in crontab?

    I cn check my php code it is working.
    and i know the time when it is activated.please tell me can this is a right command or something wrong with my hosting if it is a valid command it means there is something wrong with my hosting.

  4. #4
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    4,093
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: Run a php file using URL in crontab?

    you can try using curl instead of wget
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
    Putting your Networked Printer's scanner software to shame PHP Scanner Server
    I frequently edit my post when I have the last post

  5. #5
    Join Date
    Jun 2012
    Location
    Sweden
    Beans
    324
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Run a php file using URL in crontab?


  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    8,514
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Run a php file using URL in crontab?

    Usually you just need to run the command-line php binary:

    Code:
    1 1 * * * /usr/bin/php -q /path/to/script.php
    If the script produces output either direct it to a writable location in the script, or redirect it to a file with a pipe

    Code:
    1 1 * * * /usr/bin/php -q /path/to/script.php > /path/to/somefile
    If you need to pass a parameter like a URL to the script, append it after the script.php entry and retrieve its value in the script from the built-in $argv array. In your example, the URL will appear as $argv[0].

    If you are running a script on a remote site, then wget or curl should work. You can suppress errors via email by piping as I show above. Also are you sure that the user that is running the script has sufficient privileges?

    What do you see in /var/log/syslog when the script is run?
    Last edited by SeijiSensei; February 10th, 2013 at 09:02 PM.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Tags for this Thread

Bookmarks

Posting Permissions

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