Recently encountered in the development of a problem, the program 4th line request a URL, but the response time of the URL is very long, and my program does not use his return value, so I am wondering if I can send a request on the 4th row without waiting for his return value, directly execute the 5th line of code, OK? How do you do it if you can?
Reply content:
Recently encountered in the development of a problem, the program 4th line request a URL, but the response time of the URL is very long, and my program does not use his return value, so I am wondering if I can send a request on the 4th row without waiting for his return value, directly execute the 5th line of code, OK? How do you do it if you can?
Http://www.laruence.com/2008/04/14/318.html
Sleep (10) This 10-second operation is obviously inappropriate by the PHP process that is providing the Web service, because it will certainly cause a PHP worker process to be blocked. You might consider using Popen or Proc_open to invoke a CLI program asynchronously for some time-consuming operation.
/www/index.php
If you do not use this return, you can save this address directly to the database, which is executed by another program on the server.
If you use PHP-FPM, you can see this function.fastcgi_finish_request
You write the slow-running code behind this function.
http://php.net/manual/zh/function.fastcgi-finish-request.php
You can use PHP to extend swoole asynchronously.
-
can use multithreading, pthread extension, http://php.net/manual/en/book.pthreads.php
-
Put the request operation in the queue, execute asynchronously
array( 'timeout' => 5 ) )); $contents = file_get_contents('http://www.google.com', 0, $context);echo '5秒后到这'?>
Request with queue
Request with queue
Request with queue
This is definitely not possible!
Either you use the queue to execute.
Either you use Swoole or node. js
PHP is designed so that it can only be executed from beginning to end.
Producer/Consumer Model
A simple and rude notation that can be used to execute this logic with Register_shutdown_function ()
You do not need to return a request for the content of what you ask him to do ...