Multithreaded programming in PHP to avoid run-time limits

I know that PHP is not multithreaded, but I talked with a friend about this: if I have a big algorithmic problem that I want to solve with PHP, this is not just a solution using the curl_multi_xxx interface and running n HTTP requests on the same server. This is what I would call a multi-threaded PHP style.

Is there a problem with this in a typical web server environment? The main request waiting for "curl_multi_exec" should not count the time from the maximum duration or memory length.

I have never seen this go anywhere as a solution to prevent a script killed by too strict admin settings for PHP.

If I add this as a function to the popular PHP system, will server administrators hire a Russian mafia to avenge this hack?

+3
source share
4 answers

If I add this as a function to the popular PHP system will server administrators hire the Russian mafia hitman to avenge this hack?

No, but this is still a terrible idea, since only PHP should render web pages. Do not run large algorithms. I see that people are always trying to do this in ASP.Net. There are two correct solutions.

  • PHP (, ) , PHP- .
  • , PHP .
+5

curl, - . , .

PHP forking (pcntl_fork). , - pcntl_waitpid. "" , . , , , , , , . . forking 50 .

PHP forking, , Spencer. , , script. , .

exec("nohup /path/to/php.script > /dev/null 2>&1 & echo $!", $output);
$pid = $output[0];

exec(), , -, .

+2

- " ", ?

, Amazon EC2, , .

: " ". , , "". , .

+1

,

, php , concorrent, , , , . , imo, , php:)

0

Source: https://habr.com/ru/post/1717264/


All Articles