PHP Cron Job: How to Execute PHP file Using Crontab in Linux

There are various method to execute php file via crontab in linux. Here is the details of all the method:

Method 1: Run the php script using URL from the crontab

If your php script can be invoked using an URL, you can lynx, or curl, or wget to setup your crontab as shown below.

The following script executes the php script (every hour) by calling the URL using the lynx text browser. Lynx text browser by default opens a URL in the interactive mode. However, as shown below, the -dump option in lynx command, dumps the output of the URL to the standard output.

00 * * * * lynx -dump http://www.t4test.com/

Method 2: Run the php script using URL from the crontab

The following script executes the php script (every 5 minutes) by calling the URL using CURL. Curl by default displays the output in the standard output. Using the “curl -o” option, you can also dump the output of your script to a temporary file as shown below

*/5 * * * * /usr/bin/curl -o temptest.txt http://www.t4test.com

 

Method 3: Run the php script using URL from the crontab

The following script executes the php script (every 10 minutes) by calling the URL using WGET. The -q option indicates quite mode. The “-O temp.txt” indicates that the output will be send to the temporary file.

*/10 * * * * /usr/bin/wget -q -O temp.txt http://www.t4test.com

Method 4: Run the php script using URL from the crontab

Just like how you call your shell script , use the php executable, and call the php script from your crontab as shown below.

To execute myscript.php every 1 hour do the following:

# crontab -e
00 * * * * /usr/local/bin/php /home/satya/testscript.php

To know more about Cron job scheduling in linux click here or follow the below link

http://blog.eduguru.in/linux-cron-job-schedule-job-in-linux-crontab/

 

Related Posts

  • 45
    In all Operating system there option to schedule a job/activity that should be run on particular time interval. Here is an introduction to job scheduler in linux, called crontab. Cron allows tasks to run automatically in the background at fixed time or time intervals depending upon the necessity of the…
    Tags: crontab, cron, job, file, linux
  • 41
    The vi Editor http://t4test.com/blog/unix-linux-shell-script-introduction-to-shell-scripting/ http://t4test.com/blog/read-making-shell-script-interactive/ http://t4test.com/blog/cpio-a-backup-program/ Backup Using TAR Backing up your files using tar is very simple you just type a little command. tar -cvpzf /BackupDirectory/backupfilename.tar.gz /ImportantData/directory/path Let’s suppose i have directory called /imp-data on root and i want to make backup of this directory including sub directories on…
    Tags: file, crontab, cron, linux, job, script
  • 32
    A Shell script for killing slow MySQL queries: #!/bin/sh # Credentials for a MySQL user with PROCESS, SUPER permissions USERNAME= PASSWORD= # MySQL Server location HOST= PORT=3306 TIMEOUT=60 # 1 minute TARGET_USER= # MySQL user to monitor MYSQL="mysql -u $USERNAME --password=$PASSWORD -h $HOST -P $PORT -B" $MYSQL -N -e 'SHOW…
    Tags: job, cron, linux, crontab, script

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: