Home > Backend Development > PHP Tutorial > Implementing multi-threading in php_PHP tutorial

Implementing multi-threading in php_PHP tutorial

WBOY
Release: 2016-07-13 17:32:40
Original
817 people have browsed it

Implement multi-threading in

php (as the current mainstream development language) ? When you see this title, you must think I am crazy... but in fact I really did it.

The following are some of my methods, which have been tested. It is indeed possible.

We know that php(as the current mainstream development language) itself does not support multi-threading. But our WEB server supports multi-threading.

In other words, it can be accessed by multiple people at the same time. This is also what I implemented in php (as the current mainstream development language) The basis of multi-threading.

Assume that we are running a.php (as the current mainstream development language) file. But in the program, I also request the WEB server to run another b.php(as the current mainstream development language)

Then these two files will be executed at the same time.

(PS: After a link request is sent, The WEB server will execute it, regardless of whether the client has exited)

Sometimes, what we want to run is not another file, but a part of the code in this file. What should we do?

In fact, you can use parameters to control which program a.php (as the current mainstream development language) runs.

Let’s look at an example:

//a.php(as the current mainstream development language)


php(as the current mainstream development language)Code: --- -------------------------------------------------- --------------------------

(as the current mainstream development language)
function runThread()
{
$fp = fsockopen(localhost, 80, $errno, $errmsg);

fputs($fp, "GET /a.php(as the current mainstream development language)?act=b "); //The second parameter here is the request header specified in the HTTP protocol. 🎜>
function a()
{
$fp = fopen(result_a.log, w);
fputs($fp, Set in . Date(h:i:s, time() ) . (double)microtime() . " ");

                                                                                   >         fputs($fp, Set in . Date(h:i:s, time()) . (double)microtime() . " ");




http://www.bkjia.com/PHPjc/508699.html

www.bkjia.com

true


http: //www.bkjia.com/PHPjc/508699.html

TechArticle

How to implement multi-threading in php (as the current mainstream development language)? When you see this title, you must think that I Crazy...but in fact I really did it. Here are some of my practices, which have been implemented...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template