Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Concurrency via Cron

I have a few scripts that need to run concurrently as separate processes. My plan is to have a cron job that executes multiple instances of these scripts at a set interval. Is this a good idea? What are the pros/cons to this approach? Are there any other options I need to consider?

Bottomline: I'm trying to mimic multithreading. Any race conditions will be handled via code (e.g. setting statuses in DB, etc.). The scripts are supposed to do processing intensive tasks (e.g. creating thumbnails, etc.).

like image 744
StackOverflowNewbie Avatar asked Sep 01 '10 23:09

StackOverflowNewbie


1 Answers

You can use forking. The startup script would load all the default configurations and initializations, then fork child processes to do the processing. It could then monitor the processes to see if they are still running. http://php.net/manual/en/function.pcntl-fork.php

like image 67
Brent Baisley Avatar answered Oct 03 '22 16:10

Brent Baisley