Olivier Giniaux
Olivier Giniaux

Reputation: 950

How to schedule the execution of a PHP script?

I want to run a php script located on my FTP every hour (precisely XX:00).

My host have a feature called "CRON tasks" to do this. However, I can't pass parameters in the URL (it has to end with .php) and also I found out that the execution was quite approximate (+/- 30 seconds).

I don't have a machine at home running 24h/24h.

This php script only has an SQL request, so I tried to schedule the request directly from mySQL PhpMyAdmin, however I need SUPER rights to do this (and I don't have it).

Is there a solution for this ? Thank you in advance.

Upvotes: 1

Views: 110

Answers (1)

spencer7593
spencer7593

Reputation: 108370

You could execute curl or wget from cron. You'd supply the URL (with parameters) you want to execute as an argument.

(This assumes that your .php script is available through a web server. I only mention that, because I don't understand what you mean by "located on my FTP".)

As far as the time of execution of a cron task being "approximate (+/-30 seconds)", I've never observed a cron task begin executing before the scheduled time.


FOLLOWUP

If it's only SQL statements that you need to execute, then .php shouldn't be a requirement. You could use the mysql command line client. For example, you can throw together a small shell script that calls mysql, and then schedule the execution of the shell script with cron.

Upvotes: 1

Related Questions