We help IT Professionals succeed at work.

Run PHP script as daemon and auto scale

drupal_100
drupal_100 asked
on
315 Views
Last Modified: 2014-12-16
Run PHP script as daemon and auto scale

Have a PHP program to process events stored in database,
event table
id      description
1      event 1
2       event 2
3      event 3
...

process_event.php
<?php
do loop {
get an event from table
process the event
remove the event from table
}
?>

Want to run PHP program as daemon.
process_event.sh
#!/bin/bash
nice php process_event.php
 
Here it only runs a single worker.
Want to auto scale additional workers when needed.
For example, when table has 10 events, run 1 worker,
when table has 20 events, run 2 workers,
and automatically scale to run more or less workers according to number of events.
Comment
Watch Question

gr8gonzoConsultant
CERTIFIED EXPERT

Commented:
So what is the question?
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
$pid = pcntl_fork();
fork process to scale up.

Author

Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for drupal_100's comment #a40483418

for the following reason:

Get answer
gr8gonzoConsultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2015

Commented:
Your request does not concern programming, or manually forking process where you should be using a thread.

Both PHP-FPM and apache mod_fcgi exactly scales dynamically (untill 1024 parallel requests without tuning, that yields 20x that in users of site using it)
Top Expert 2015

Commented:
You need to explain better.
gr8gonzoConsultant
CERTIFIED EXPERT

Commented:
My recommendation: Split points:
http:#a40435577 (gheist) - 400 points
http:#a40483528 (gr8gonzo) - 100 points
Top Expert 2015

Commented:
I think both ways is acceptable like 50/50 I move threads out of process while you emphasize on hardships of thread programming.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.