国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php是如何實現多線程并發的

2020-03-22 18:50:16
字體:
來源:轉載
供稿:網友
PHP 默認并不支持多線程,要使用多線程需要安裝 pthread 擴展,而要安裝 pthread 擴展,必須使用 --enable-maintainer-zts 參數重新編譯 PHP,這個參數是指定編譯 PHP 時使用線程安全方式。

<?php if(function_exists('date_default_timezone_set')) { date_default_timezone_set('PRC'); } function a() { $time = time(); sleep(3); $fp = fopen('result_a'.$time.'.log', 'w'); fputs($fp, 'Set in ' . Date('h:i:s', time()) . (double)microtime() . "rn"); fclose($fp); } function b() { $time = time(); sleep(3); $fp = fopen('result_b'.$time.'.log', 'w'); fputs($fp, 'Set in ' . Date('h:i:s', time()) . (double)microtime() . "rn"); fclose($fp); } if(!isset($_GET['act'])) $_GET['act'] = 'a'; if($_GET['act'] == 'a') { a(); } else if($_GET['act'] == 'b') b(); ?>

以上代碼,在本地寫入一個文件。

PHP多線程讀寫文件:

如果你訪問 localhost/a.php 在兩個瀏覽器標簽盡可能快的同時打開,發現兩個文件創建時間相差為3秒

但是如果你訪問localhost/a.php?act=b 另一個訪問/a.php?act=a 你發現兩個文件創建的時間幾乎差不多。

對于apache來說同樣的url意味著一個線程(我們或者說是進程),但是不同的URL意味著可以 并發 。

如果php內部有下載的動作

function runThread() { down("http://localhost/test/a.php?act=a"); } if($_GET['act'] == 'run') { echo 'start:'; runThread(); echo ' End'; }

http://localhost/test/a.php?act=run

http://localhost/test/a.php?act=run&s=2

只要主訪問的url不同,則認為是不同的進行,意味著并發。文件創建時間不為3秒

本地有html' target='_blank'>Linux服務器的朋友也可以借助linux來進行模擬并發

<?php for ($i=0;$i<10;$i++) { echo $i; sleep(5); } ?>

上面存成test.php, 然后寫一段SHELL代碼

#!/bin/bashfor i in 1 2 3 4 5 6 7 8 9 10dophp -q test.php &doneFixed a bug where :doc:`Image Manipulation Library <libraries/image_lib>` didn't escape image source paths passed to ImageMagick as shell arguments.Fixed a bug (#861) - :doc:`Database Forge <database/forge>` method create_table() incorrectly accepts field width constraints for mssql/SQLSRV integer-type columns.Fixed a bug (#4562) - :doc:`Cache Library <libraries/caching>` didn't check if Memcached::quit() is available before calling it.Fixed a bug (#4563) - :doc:`Input Library <libraries/input>` method request_headers() ignores $xss_clean parameter value after first call.Fixed a bug (#4605) - :doc:`Config Library <libraries/config>` method site_url() stripped trailing slashes from relative URIs passed to it.Fixed a bug (#4613) - :doc:`Email Library <libraries/config>` failed to send multiple emails via SMTP due to "already authenticated" errors when keep-alive is enabled.Fixed a bug (#4633) - :doc:`Form Validation Library <libraries/form_validation>` ignored multiple "callback" rules for empty, non-required fields.Fixed a bug (#4637) - :doc:`Database <database/index>` method error() returned FALSE with the 'oci8' driver if there was no error.Fixed a bug (#4647) - :doc:`Query Builder <database/query_builder>` method count_all_results() doesn't take into account GROUP BY clauses while deciding whether to do a subquery or not.Fixed a bug where

相關推薦:

php 實現多線程,php多線程

以上就是php是如何實現多線程并發的的詳細內容,更多請關注 其它相關文章!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 自治县| 汶上县| 逊克县| 尉氏县| 龙川县| 额敏县| 鄂伦春自治旗| 依安县| 浦城县| 抚顺县| 柞水县| 西平县| 庆云县| 客服| 抚远县| 从化市| 南开区| 龙岩市| 北辰区| 抚远县| 合阳县| 清水河县| 九龙城区| 成都市| 田东县| 溧阳市| 乌拉特前旗| 牙克石市| 台东县| 灵川县| 葵青区| 永善县| 宁蒗| 竹北市| 台安县| 修文县| 仪征市| 刚察县| 左云县| 昌乐县| 通山县|