Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP Manual > pcntl_signal - Installs a signal handler





ลองใช้ค้นหาข้อมูล


   
Bookmark.

pcntl_signal

(PHP 4 >= 4.0.7, PHP 5)

pcntl_signalInstalls a signal handler

Description

bool pcntl_signal ( int $signo , callback $handler [, bool $restart_syscalls ] )

The pcntl_signal() function installs a new signal handler for the signal indicated by signo .

Parameters

signo

The signal number.

handler

The signal handler which may be the name of a user created function, or method, or either of the two global constants SIG_IGN or SIG_DFL.

Note: Note that when you set a handler to an object method, that object's reference count is increased which makes it persist until you either change the handler to something else, or your script ends.

restart_syscalls

Specifies whether system call restarting should be used when this signal arrives and defaults to TRUE.

Return Values

Returns TRUE on success or FALSE on failure.

ChangeLog

Version Description
4.3.0 The restart_syscalls parameter was added.
4.3.0 The ability to use an object method as a callback became available.
4.3.0 As of PHP 4.3.0 PCNTL 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 must use the declare() statement to specify the locations in your program where callbacks are allowed to occur for the signal handler to function properly (as used in the above example).

Examples

Example #1 pcntl_signal() example

<?php
// tick use required as of PHP 4.3.0
declare(ticks 1);

// signal handler function
function sig_handler($signo)
{

     switch (
$signo) {
         case 
SIGTERM:
             
// handle shutdown tasks
             
exit;
             break;
         case 
SIGHUP:
             
// handle restart tasks
             
break;
         case 
SIGUSR1:
             echo 
"Caught SIGUSR1...\n";
             break;
         default:
             
// handle all other signals
     
}

}

echo 
"Installing signal handler...\n";

// setup signal handlers
pcntl_signal(SIGTERM"sig_handler");
pcntl_signal(SIGHUP,  "sig_handler");
pcntl_signal(SIGUSR1"sig_handler");

// or use an object, available as of PHP 4.3.0
// pcntl_signal(SIGUSR1, array($obj, "do_something");

echo"Generating signal SIGTERM to self...\n";

// send SIGUSR1 to current process id
posix_kill(posix_getpid(), SIGUSR1);

echo 
"Done\n"

?>



ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่