作者clifflu (缺钱啦 @@)
看板PHP
标题Re: [请益] multithread
时间Tue Oct 25 11:27:30 2005
※ 引述《ojinjin (小欧)》之铭言:
: 请问有没有办法在 php 写出 multithread 的程式?
: google 只有找到在 linux 下的做法
: 谢谢
1. php 本身没有提供 create thread 的函式或功能.
2. 如果 httpd 是使用 apache 的话, 每一个 request 是来自一个 thread (吧 XD)
3. php 能够以 pcntl_fork 的方式产生 process.
4. 你也可以透过 execution 的方式, 产生子 process.
你也可以决定母 process (.php) 要不要等子 process 跑完.
要在不同的 php process 间沟通, 你能够透过:
1) files (包含 ram-drive, CDRom, DB 等)
2) Memory (SHM, global variables, server/env variables)
3) stdin/stdout (using $argv & outputs)
4) session / cookie (under HTML/XHTML)
如果你有某些演算法, 需要多个 thread 来增进效能的话,
建议用其他语言在 server side 写出程式由 php 呼叫,
另写一页面用以取得执行结果, 会比较适合. (尚未完成时显示执行进度是个好主意)
另外, 你可能会需要 set_time_limit 来改变执行时间,
相关请见
http://tw.php.net/manual/en/function.set-time-limit.php
--
鬼压床怎麽办
骑上去啊
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.217.134
1F:推 accordingto:push~ 10/25 15:06