php loop problem
巴扎黑
巴扎黑 2017-05-16 13:15:15
0
3
368

while($a<1000){

$a++;
foo();

}

If foo() consumes a lot of resources, needs to be connected to the Internet, needs to add, delete, modify and check many databases, etc., do we have to wait for foo() to finish executing before starting the next cycle?

巴扎黑
巴扎黑

reply all(3)
滿天的星座

Execution rights issue in yes.php..

Only after the function is executed, the execution right will be returned to the calling place and the following code will continue to be executed.

刘奇

Yes. That’s why it’s called single thread

滿天的星座

The next loop will not be executed until the foo function is executed. PHP is a single-process blocking execution. Asynchronous execution requires swoole extension, or use pcntl extension to implement multi-process under Linux, and put time-consuming operations into sub-processes for execution. You can use pthreads extension to implement multi-threading, but it must be executed under the TS version of PHP

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template