|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-07-01 18:05 UTC] jason@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 18:00:01 2025 UTC |
Configure Command: ./configure --with-imap --with-mysql --enable-sockets --enable-pcntl Example: #! /usr/local/bin/php -q <?php error_reporting(E_ALL); set_time_limit(0); function sig_handler($signo) { switch($signo) { case SIGTERM: // handle shutdown tasks echo "Got SIGTERM! Closing sockets and exiting...\n"; @socket_close($msgsock); @socket_close($sock); exit; break; case SIGINT: // handle shutdown tasks echo "Got SIGINT! Closing sockets and exiting...\n"; @socket_close($msgsock); @socket_close($sock); exit; break; default: // handle all other signals } } $address = "127.0.0.1"; $port = 5550; echo "Installing signal handler...\n"; if (pcntl_signal(SIGTERM, "sig_handler")) echo "SIGTERM installed!\n"; if (pcntl_signal(SIGINT, "sig_handler")) echo "SIGINT installed!\n"; if (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) < 0) { echo "socket_create() failed: reason: " . strerror($sock) . "\n"; exit; } if (($ret = socket_bind($sock, $address, $port)) < 0) { echo "socket_bind() failed: reason: " . strerror($ret) . "\n"; exit; } if (($ret = socket_listen($sock, 5)) < 0) { echo "socket_listen() failed: reason: " . strerror($ret) . "\n"; exit; } do { echo "Listening...\n"; if (($msgsock = socket_accept($sock)) < 0) { echo "socket_accept() failed: reason: " . strerror($msgsock) . "\n"; break; } else { socket_write($msgsock, "READY\n", 6); } do { break 1; } while(true); socket_close($msgsock); } while(true); socket_close($sock); ---END--- This peace of code is waiting for a socket connection with socket_accept() and has installed signal handlers for SIGINT and SIGTERM! I'm expecting that catching signal SIGINT should enter the function sig_handler() even if the script is waiting for a connection at this moment. That does not happen, any signal installed with pcntl_signal() is ignored (of course not SIGKIL) while waiting for connections with socket_accept(). The script does not enter the function sig_handler(). Kind regards Chris