mirror of
https://github.com/php/doc-ru.git
synced 2025-07-20 16:42:29 +00:00

* Update pattern.matching.xml to en * Update createstopped.xml to en * Update construct.xml to en * Update createstopped.xml исправил формулировку * Update createstopped.xml to en * Update construct.xml to en * Update createstopped.xml to en * Update construct.xml to en * Update construct.xml Добавил кавычки к названию страницы * Update createstopped.xml to en * Update construct.xml to en * Update createstopped.xml to en * Update createstopped.xml исправил ошибку * Update construct.xml to en * Update createstopped.xml to en * Update construct.xml to en * Update createstopped.xml to en * Update prev.xml to en * Update stat.xml to en * Update construct.xml to en * Update createstopped.xml to en * Update set.xml to en * Update clear.xml to en * Update feed.xml to en * Update invoke.xml to en * Update setcallback.xml to en * Update book.xml to en * Update event.callbacks.xml to en * Update event.constructing.signal.events.xml to en * Update event.flags.xml to en * Update event.constructing.signal.events.xml исправил формулировку * Update event.persistence.xml to en * Update event.xml to en * Update eventbase.xml to en * Update eventbuffer.xml to en * Update eventbufferevent.about.callbacks.xml to en * Update eventbufferevent.xml to en * Update eventconfig.xml to en * Update eventsslcontext.xml to en * Update eventutil.xml to en * Update setup.xml to en * Update construct.xml to en * Update free.xml to en * Update pending.xml to en * Update event.callbacks.xml исправил формулировку * Update set.xml to en * Update set.xml формулировка * Update settimer.xml to en * Update signal.xml to en * Update timer.xml to en * Update free.xml to en * Update getfeatures.xml to en * Update gotexit.xml to en * Update gotstop.xml to en * Update loop.xml to en * Update addbuffer.xml to en * Update copyout.xml to en * Update drain.xml to en * Update prependbuffer.xml to en * Update readline.xml to en * Update search.xml to en * Update searcheol.xml to en * Update search.xml исправил формулировку * Update unlock.xml to en * Update connecthost.xml to en * Update construct.xml to en * Update createpair.xml to en * Update disable.xml to en * Update enable.xml to en * Update free.xml to en * Update getdnserrorstring.xml to en * Update readbuffer.xml to en * Update setcallbacks.xml to en * Update setwatermark.xml to en * Update setwatermark.xml Исправил ошибку * Update sslfilter.xml to en * Update sslsocket.xml to en * Update avoidmethod.xml to en * Update setmaxdispatchinterval.xml to en * Update loadhosts.xml to en * Update parseresolvconf.xml to en * Update setoption.xml to en * Update accept.xml to en * Update setallowedmethods.xml to en * Update setcallback.xml to en * Update setdefaultcallback.xml to en * Update makerequest.xml to en * Update addheader.xml to en * Update findheader.xml to en * Update getconnection.xml to en * Update sendreplystart.xml to en * Update construct.xml to en * Update construct.xml to en * Update setsocketoption.xml to en * Update pattern.matching.xml to en
97 lines
3.1 KiB
XML
97 lines
3.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- EN-Revision: 23ea6be076881a34e1d454e9680968ece085f7f6 Maintainer: rjhdby Status: ready -->
|
||
<!-- Reviewed: no -->
|
||
<chapter xml:id="event.constructing.signal.events" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||
<title>Создаёт события для сигналов</title>
|
||
<para>
|
||
Модуль Event умеет отслеживать сигналы в стиле интерфейса POSIX.
|
||
Обработчики для сигнала создают через
|
||
метод <methodname>Event::__construct</methodname>
|
||
с флагом
|
||
<constant>Event::SIGNAL</constant>
|
||
или фабричный метод
|
||
<methodname>Event::signal</methodname>.
|
||
</para>
|
||
<example>
|
||
<title>Пример обработки сигнала <literal>SIGTERM</literal></title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
|
||
/*
|
||
Запуск в окне терминала:
|
||
|
||
$ php examples/signal.php
|
||
|
||
В другом терминальном окне отыщите этот процесс
|
||
и отправьте процессу сигнал SIGTERM:
|
||
|
||
$ 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
|
||
|
||
В первом терминале появится следующее:
|
||
|
||
Пойман сигнал 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 "Пойман сигнал $no\n";
|
||
$this->base->exit();
|
||
}
|
||
}
|
||
|
||
$base = new EventBase();
|
||
$c = new MyEventSignal($base);
|
||
|
||
$base->loop();
|
||
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
<para>
|
||
Обратите внимание, callback-функции
|
||
запускаются внутри событийного цикла после получения
|
||
сигнала, поэтому для них безопасно вызывать
|
||
функции, которые лучше не запускать из стандартных
|
||
обработчиков сигналов интерфейса POSIX.
|
||
</para>
|
||
<para></para>
|
||
<para>
|
||
Дополнительную информацию даёт раздел
|
||
<link xlink:href="http://www.wangafu.net/~nickm/libevent-book/Ref4_event.html#_constructing_signal_events">Fast portable non-blocking network programming with Libevent, Constructing Signal Events</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
|
||
-->
|