Web Hosting Talk







View Full Version : How to set PHP file in cron on Plesk server


dragonhawk
08-17-2002, 12:00 AM
Just wondering if anyone has done this before.

Write a PHP script that needs to be run once a day. How would you place such a file in cron so that it is run once a day.

Atif Munir
08-17-2002, 01:51 AM
Hi,
Just install php*tar.gz in the home folder of a user like /home/username/php with the following commands.
$tar -xzvf php*tar.gz
$./configure --prefix=/home/username/php/justphp
$make
$make install


Now your may run php scripts like this
$/home/username/php/justphp/bin/php filename.php

Atif

bobcares
08-17-2002, 06:22 AM
Say you are user poornam and you want to run a php program(say http://www.poornaminc.com/exp.php) from cron and output the results to a file /home/poornam/phptest2


SSH into the system as poornam
create a file (say /home/poornam/cronjob)

Add the folllowing lines to it

SHELL=/bin/bash
MAILTO=sangeetha@poornam.com
0 * * * * /usr/bin/wget -O/home/poornam/testphp2

http://www.poornaminc.com/exp.php

The above syntax means that at the start(0) of every hour(*) of every day(*) of every month(*) of every year(*), wget will run the exp.php and output the contents to testphp2. And when this runs, it will send a mail to

sangeetha@poornam.com
Save the above file

now run crontab /home/poornam/cronjob

This will automatically add it to cron and execute it at the designated time
If you do not want to output the results anywhere simply omit
-O/home/poornam/testphp2

To view the contents of cron simply type crontab -l
to remove tasks from cron simply type crontab -r


Say you are user root and you want to run a system critical php program(say http://www.poornaminc.com/exp.php) every hour from cron and output the results to a file /home/poornam/phptest2 here's what you do

ssh into the system as root
create a file say( /etc/cron.hourly/phpcron)
Add the folllowing lines to it



#!/bin/sh

/usr/bin/wget -O/home/poornam/testphp2 http://www.poornaminc.com/exp.php
save and chmod to 755
Here cron automatically reads /etc/crontab , detects all scripts in /etc/cron.hourly (in our case phpcron) )and executes them
For hourly , daily, weekly and monthly, store your scripts in /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly respectively

bitserve
08-17-2002, 01:26 PM
Besides wget, you could probably use lynx.

dragonhawk
08-17-2002, 08:11 PM
Thanks for all the help :) I'll be sure to try it out and report back :D