cron job

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

cron job

Post by superman »

how to set up a cron job that work with PHP? is it very complicated?
is it can run a PHP file in a specific time?
what do i need? or any tutorial that teach about this?
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

2 ways:

If you have the CLI version of PHP installed you can simply call the script with

Code: Select all

php scriptname.php
If you don't have CLI PHP you could install a cronjob that uses wget or curl to call the script on the webserver.
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

Post by superman »

if my php is not a CLI version, what is the first thing that i need to do?
or create cronjob?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Just some FYI. You can run a cron job with either a CLI or CGI install. I've been running php based jobs for two years now on machines with CGI installations . At the top of the script, you will need a line like the one below telling the system where the php executable is.

#!/usr/local/bin/php -q
#!/usr/local/bin/php (If you have a CLI install)

You will also need to understand the crontab commands. Just do a man crontab from the command line to get information on how to do it.

There are also a number of tutorials on creating cron files that can be found on google.

Lastly, I'm assuming you are on a Linux/Unix type system. If you are on Windows, there are options, but you have to find them on google. I've explored them, but it's been a while and I don't remember where they are.

Cheers,
BDKR
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

is it need to type someting in linux command line?
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

Post by superman »

how can i know the CLI or CGI installed on my machine?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

In Windows,

C:\PHP\> php.exe php_file.php

On Unix:

[root@localhost /]# php php.file.php
(Assuming `php` is in your $PATH)
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

Post by superman »

is it just type #!/usr/local/bin/php on the page that need to run?
need to configure something in linux server or type in some command line?
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

Post by superman »

i put all the PHP file inside this directory

http://10.1.1.200/B0300549/public_html/phpweb/cron.php

the cron.php is the page that i need to run


if i want to run the cron.php once a year (every January), is it the correct way that i wrote?

crontab -e
* * * 1 * php /10.1.1.200/B0300549/public_html/phpweb/cron.php


then, am i need to put this line on top of the cron.php

#!/10.1.1.200/B0300549/public_html/phpweb/php
Post Reply