cosy
cosy

Reputation: 572

Php run cronjobs

How can i run an cron job from php, and the cron to start in that moment? I have a sitemap script, and i want to turn to a sitemap link, without waiting for him to do his job, to send information to call my job horn Sitemap.

Sorry my English

Upvotes: 0

Views: 900

Answers (4)

Gordon
Gordon

Reputation: 316939

An alternative to Cron would be to use Gearman

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages.

There is a PHP extension for Gearman that provides an API to write client and workers as well.

Also see this four part series The Mysteries of Asynchronous Processing and the chapter on Process Control in Pragmatical PHP Programming

Upvotes: 1

James Anderson
James Anderson

Reputation: 27478

A cron job needs to be entered into the "cron" schedule to run at a particular time.

My guess is that there is a script in your installation which is normally started by cron and you want to start it when your php program detects some condition.

You need to find out where the crontab script is located (try "crontab -e" for a list of currently defineded cron jobs) and start it uing a php system() or exec() command.

Upvotes: 1

Pekka
Pekka

Reputation: 449385

This totally depends on your server setup, but usually it's not possible to install a cron job from plain PHP because of user rights and other restrictions.

Also, I don't think you are really looking for a cron job, but for how to start a background process using exec(). See for example the method the OP describes in this question. The User Contributed Notes to exec() in the PHP manual also contain valuable tips.

Upvotes: 2

Sarfraz
Sarfraz

Reputation: 382616

See cron job tutorial here.

Upvotes: 1

Related Questions