mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-04-25 09:38:03 +02:00
bcea04f6f8
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@334295 c90b9560-bf6c-de11-be94-00142212c4b1
96 lines
2.8 KiB
XML
96 lines
2.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 59a1bbcb6f7a1e74a640d7ec2890cc6a12f19b52 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<chapter xml:id="event.constructing.signal.events" xmlns:phpdoc="http://php.net/ns/phpdoc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<title>Construction d'un événement de type signal</title>
|
|
<para>
|
|
Un événement peut aussi surveiller les signaux de style POSIX.
|
|
Pour construire un gestionnaire pour un signal, utilisez la méthode
|
|
<methodname>Event::__construct</methodname> avec le drapeau
|
|
<constant>Event::SIGNAL</constant> ou la méthode factorielle
|
|
<methodname>Event::signal</methodname>.
|
|
</para>
|
|
<example>
|
|
<title>Gestion d'un signal <literal>SIGTERM</literal></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/*
|
|
Lancez cet exemple dans un terminal :
|
|
|
|
$ php examples/signal.php
|
|
|
|
Dans un autre terminal, trouvez le pid, et lancez le signal SIGTERM, i.e.:
|
|
|
|
$ ps aux | grep examp
|
|
ruslan 3976 0.2 0.0 139896 11256 pts/1 S+ 10:25 0:00 php examples/signal.php
|
|
ruslan 3978 0.0 0.0 9572 864 pts/2 S+ 10:26 0:00 grep --color=auto examp
|
|
$ kill -TERM 3976
|
|
|
|
Dans le premier terminal, vous devriez attraper ceci :
|
|
|
|
Caught signal 15
|
|
*/
|
|
class MyEventSignal {
|
|
private $base, $ev;
|
|
|
|
public function __construct($base) {
|
|
$this->base = $base;
|
|
$this->ev = Event::signal($base, SIGTERM, array($this, 'eventSighandler'));
|
|
$this->ev->add();
|
|
}
|
|
|
|
public function eventSighandler($no, $c) {
|
|
echo "Caught signal $no\n";
|
|
$this->base->exit();
|
|
}
|
|
}
|
|
|
|
$base = new EventBase();
|
|
$c = new MyEventSignal($base);
|
|
|
|
$base->loop();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<para>
|
|
Notez que les fonctions de rappel d'un signal sont exécutées dans la
|
|
boucle d'événement après que le signal ne soit survenu, aussi,
|
|
il est plus sécurité pour le signal d'appeler des fonctions depuis la boucle
|
|
que vous n'êtez pas supposé d'appeler depuis un gestionnaire de signaux
|
|
POSIX classique.
|
|
</para>
|
|
<para></para>
|
|
<para>
|
|
Voir aussi la
|
|
<link
|
|
xlink:href="http://www.wangafu.net/~nickm/libevent-book/Ref4_event.html#_constructing_signal_events">
|
|
programmation réseau facile, protable et non bloquante avec Libevent ; Construction
|
|
d'un événement de type signal</link>.
|
|
</para>
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|