Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about timed tasks for PHP 1

Status
Not open for further replies.

jisoo23

Programmer
Joined
Jan 27, 2004
Messages
192
Location
US
Hello all,

I'm not sure if anyone will know but I thought I'd ask. Has anyone ever implemented a PHP-based program on a website that will do a specific task based on a timetable? For example, that program would scan a MySQL database every night at midnight and do it's required duties. This would be a sort of self-maintenance system. I know you could probably do it in Java or C++ or something, but I was wondering if anyone had accomplished this in PHP or similar web-based language?

Thanks,
Jisoo23
 
It depends on the OS. For Linux type OS there is CRON that can be used to run PHP scripts on a schedule. Then it also depends on the PHP installation, if it is e.g. Apache module or CGI.

For Windows OS there is also a scheduling application.

So, the answer is: Yes, it has been done and is quite common.
 
Ok cool, now one more question. What about if you're on a virtual server-based website hosting service that does not support modifications to their Apache module or CGI? I'm not sure if they support the installation of crons? But that might be something I'll have to ask them myself.

Thanks,
Jisoo23
 
Ok it looks like my webhost provider does support crons. Does anyone have any good tutorials on how to create crons that run PHP pages?

Thanks,
Jisoo23
 
A cron job is simply a program.

The gotcha is that you're going to have to write PHP code that can be used from the command line.

On *nix OSes, you have to provide the shebang line which tells the system what command interpreter to use to run the script. The script will have to look something like:

#! /usr/bin/php
<?php
print 'foo!';
?>

The shebang is the &quot;#!&quot; twin characters. That line must begin at the first position of the first line of the script and must include the full path to the PHP command-line interpreter. Ask your HSP what that path should be.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top