Newbie Prog
Newbie Prog

Reputation:

How can I easily and simply schedule a cron job in PHP?

How can I easily and simply schedule a cron job in PHP? Rails has BackgroundRB...

Upvotes: 1

Views: 3171

Answers (5)

Diego Palomar
Diego Palomar

Reputation: 7061

I recommend http://www.phpjobscheduler.co.uk/

Upvotes: 1

mixdev
mixdev

Reputation: 2844

There is PHP-Resque, a PHP port of the queue&background process framework written by GitHub guys.

Upvotes: 1

Till
Till

Reputation: 22408

Here's a semi-PHP solution to add to a crontab:

$cmd  = 'crontab -l > /tmp/crontab.bak'; // preserve current crontab
$cmd .= ' && echo "*/5 * * * * /foo/bar" >> /tmp/crontab.bak'; // append new command
$cmd .= ' && crontab /tmp/crontab.bak'; // update crontab
$cmd .= ' rm /tmp/crontab.bak'; // delete temp file

exec($cmd); // execute

Upvotes: 2

jacobangel
jacobangel

Reputation: 6996

You're conflating a language with a framework. PHP doesn't have a cron scheduling any more than Ruby does. If you're using a PHP framework or cms however, there is likely some utility for cron tasks.

Here is a useful link if you have control over the machine. http://troy.jdmz.net/cron/ If you have shared hosting, there's probably some tool they'd give you for cron jobs; ask them or look in the knowledge base.

Upvotes: 0

Ross
Ross

Reputation: 46987

Most website control panels (assuming you've got cPanel or something similar running) include a crontab application. If you're on shared hosting ask your host about this.

If you're on a dedicated server and have installed cron then have a look at the crontab syntax. These commands go in crontab, usually in /etc on *nix.

Upvotes: 2

Related Questions