In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you the content of an example analysis of php multithreading. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
PHP does not support multithreading by default. To use multithreading, you need to install the pthread extension, and to install the pthread extension, you must recompile PHP with the-- enable-maintainer-zts parameter, which specifies that PHP is compiled in a thread-safe way.
Does php support multithreading?
If (function_exists ('date_default_timezone_set')) {
Date_default_timezone_set ('PRC')
}
Functiona () {
$time=time (); sleep (3)
$fp=fopen ('result_a'.$time.'.log','w')
Fputs ($fp,'Setin'.Date ('hdouble idouble) microtime (). Rn)
Fclose ($fp)
}
Functionb () {
$time=time ()
Sleep (3)
$fp=fopen ('result_b'.$time.'.log','w')
Fputs ($fp,'Setin'.Date ('hdouble idouble) microtime (). Rn)
Fclose ($fp)
}
If (! isset ($_ GET ['act'])) $_ GET [' act'] ='a'
If ($_ GET ['act'] = =' a') {
A ()
}
Elseif ($_ GET ['act'] = =' b') b ()
? >
The above code, write a file locally.
PHP multi-thread reads and writes files:
If you visit localhost/a.php and open the two browser tabs at the same time as quickly as possible, you will find that the difference in creation time between the two files is 3 seconds.
But if you visit localhost/a.php?act=b and visit / a.php?act=a, you will find that the two files are created at about the same time.
For apache, the same url means a thread (we or a process), but a different URL means concurrency.
If there is a download action inside php
FunctionrunThread () {
}
If ($_ GET ['act'] = =' run') {
Echo'start:'
RunThread ()
Echo'End'
}
As long as the url of the main access is different, it is considered to be different, which means concurrency. File creation time is not 3 seconds
Thank you for reading! This is the end of this article on "sample analysis of php multithreading". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.