Good Please understand the question

PHP, in 10 parallel threads, I perform certain actions. 10, because hosting at the same time no longer holds. Eats, but some of the scripts end up working earlier, some later. And there are still problems, and I launch the second ten, after all of the top ten have been worked out. What is not optimal

The question, as usual is simple. Can anyone explain, or scare the code, or a link, how best to run several scripts in PHP, with parallel execution, so that when you work on one of the other from the queue?

  • hosting is not installed Redis? Database? - Sergiks

1 answer 1

so you wrote it yourself - when you are working out, the next one from the queue should be included.

How to organize a queue? In an amicable way, for example, the Gearman Task Server , but under the conditions of hosting restrictions, this is questionable. Then some text file or database.

"Working" php scripts must spin constantly. It’s better not to have one php script all the time, and sometimes to restart it so that there are no memory leaks. Any bash script can constantly spin, which takes the next task and starts the next php process with it.

Tell a little more about the limitations of the host and your task.

  • The movie.php script needs to be executed XXXXX times, on my hosting, optimal performance on 10 simultaneously executed copies of the script. I run them in a cycle, 10 pieces at a time, and it turns out that some will work faster, some slower. example code in Google is of course impossible to find, what would download and poyuzat working primerchik. 9 copies of the script works for 1 second, and one 10. i.e. if 10 processes are launched in parallel, all will be executed in 10 seconds, and at this time the general queue can be moved. the boys at all node.js don't know such problems, but php has to reinvent the wheel - gforce
  • Is there something curl pulling from external url? We watched (by the way) on curl_multi_exec() - you can run N web requests from one php process - but then you have to wait until everything works out. - Sergiks
  • just now. and I want to fix it, but I don’t understand how - gforce