Major PCNTL enhancements
| From: | Jason Greene | Date: | Fri, 23 Aug 2002 04:28:32 +0000 |
| Subject: | Major PCNTL enhancements | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-87335@lists.php.net to get a copy of this message | ||
I have just recently made quite a bit of changes to the pcntl extension.
They are as follows:
Significant performance improvements
------------------------------------
PCNTL now uses ticks as the signal handle callback mechanism, which is
much faster than the previous mechanism. This change follows the same
semantics as using "user ticks". You use the declare statement to
specify the locations in your program where callbacks are allowed to
occur. This allows you to minimize the overhead of handling asynchronous
events. In the past, compiling php with pcntl enabled would always incur
this overhead, whether or not your script actually used pcntl.
There is one adjustment that all scripts currently using pcntl must make
for php 4.3, which is to either use declare on a section where you wish
to allow callbacks, or to just enable it across the entire script using
the new global syntax of declare.
i.e.
<?php
print "do something\n";
declare (ticks = 1) {
print "Signals callbacks can occur here\n";
}
?>
-or-
<?php
declare (ticks=1);
//do stuff
?>
The speedup rate for scripts which did not use pcntl, yet used a version
of php with pcntl compiled in came to around 30%. The rate of
improvement for scripts which used fully used pcntl came to roughly 14%.
Object method signal handles
----------------------------
Yes, the much requested ability to use an object method as a callback is
now here. Thanks go to Alan, and Marcus for sending me the initial
patches for this behavior,
To use this method simply pass pcntl_signal an object, method array as
the handle.
i.e.
pcntl_signal(SIGUSR1, array($obj, "do_something");
One important thing to note is that when you set a handler to an object
method, that object's reference count is increased, making it persist
until you either change the handler to something else, or your script
ends.
System call restarting now optional
------------------------------------
pcntl_signal now takes a third optional parameter, which specifies
whether system call restarting should be used when this signal arrives.
This defaults to true (which should be more common), but you can now
disable it.
In order to explain the reasoning behind why you would want to do this,
allow me to show how signal callbacks work internally:
When a signal is triggered, it is most likely not safe to immediately
execute your handle. So, the event is recorded, and the handle is called
at the soonest available safe time slot in the engine. This means that a
signal handle can only be called between each php/zend opcode. The
problem with this, is that if you have a signal occur during a long
waiting system call, the php handle never gets a chance to be called.
This feature alleviates this problem by causing all signals with restart
disabled to abort any long system call in progress.
I will be updating the documentation sometime soon, but if you have any
questions this, feel free to email me..
Thanks
-Jason