php教程

pthreads

User Contributed Notes

mckaygerhard at gmail dot com 26-Sep-2018 03:01
mayority of that problems only happned for guindows, .. porr os
anonymous at example dot com 02-Jun-2017 03:19
Here are some notes regarding PHP pThreads v3 that I have gathered:
-namespace: It does not understand namespaces.
-globals: It won't serialize GLOBALS at all! And will not register new ones.
-classes: It registers new classes okay.
-functions: Will not register ANY functions - they must all be in static classes. It does understand PHP native functions.
-consts: previous constants will transfer over. Don't make any new ones thou!
-pThreads only work in CLI - of course!
-If a thread crashes it automatically gets recreated.
-In order to 'force kill' any thread the parent must be killed. Or wait until all other tasks queued are complete and then terminate.
-Anything registered in a pThread does not seem to join the main thread ... which is good!
-pThreads seem to be very powerful on multi-core environments, just need to be careful on system resources... it can and will lock up a system if mis-configured.
-Finally, finding help for PHP pThreads is slim to none... especially v3!

Good luck!
r3x at engelhardt-stefan dot de 17-Nov-2015 06:17
If you try to test threading, remember to let php think slow:

Skript: -- C:\Webserver\htdocs>php mttest.php

<?php
class My extends Thread{
    function
run(){
        for(
$i=1;$i<10;$i++){
            echo
Thread::getCurrentThreadId() .  "\n";
           
sleep(2);     // <------
       
}
    }
}

for(
$i=0;$i<2;$i++){
   
$pool[] = new My();
}

foreach(
$pool as $worker){
   
$worker->start();
}
foreach(
$pool as $worker){
   
$worker->join();
}
?>

Output: -- C:\Webserver\htdocs>php mttest.php
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816

If you leave sleep() out, the cpu-time for the threads is long enough to complete the script at once.
admin at deosnet dot com 19-Aug-2014 10:01
Hello,

WARNING : When using Stackable objects in callable functions by your Threads, you must be very careful if you use it as an array. Indeed, if you do not copy your Stackable "array" in a local variable, the execution time can drop drastically !

Also, if you want to modify an array() in a function, you will also store in a local variable in order that your array is in a thread-safe context.
jasonrlester at yahoo dot com 23-Feb-2014 12:08
Note that this extension *is* a high level implementation of POSIX threads, including on Windows (which is why pthreadsV*.dll is required)

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788