php如何支援實現多線程並發

來源:互聯網
上載者:User

標籤:i++   magic   sub   request   rar   table   one   dex   test   

<?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(); ?>

以上代碼,在本地寫入一個檔案。

如果你訪問 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秒

本地有Linux伺服器的朋友也可以藉助linux來進行類比並發

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

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

#!/bin/bash

for i in 1 2 3 4 5 6 7 8 9 10

do

php -q test.php &

done

Fixed 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如何支援實現多線程並發

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.