Re: Command-line PHP script CPU usage goes sky-high, stays there--why?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jochem Maas wrote:

>> I'd be interested to see how he does the multi-threading in php.
>> Personally I'd always opt for C to write this type of thing, except
>> for perhaps the most simple cases.
>> 
> 
> any chance of an example from you too?

Sure - 

http://jessen.ch/files/distripg_main.c

It can't be compiled, but the pseudo-code goes like this:

initialize
bind() to address(es) to listen to
start a number of threads (=workers)
do until terminated
   poll() for new work 
   if new_work(), accept(), queue it, then wake up the workers. 
done

A worker thread:
initialize
do until terminated
    wait for work
    accept()
    process work
done

It wouldn't be too difficult to have threads dynamically started and
stopped depending on the amount of work queued up.



/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux