PCNTLº¯Êý×å PHP¶à½ø³Ì±à³Ì
phpÓÐÒ»×é½ø³Ì¿ØÖƺ¯Êý£¬Ê¹µÃphpÄÜÔÚ*nixϵͳÖÐʵÏÖ¸úcÒ»ÑùµÄ´´½¨×Ó½ø³Ì¡¢Ê¹ÓÃexecº¯ÊýÖ´ÐгÌÐò¡¢´¦ÀíÐźŵȹ¦ÄÜ¡£
ÒýÓÃ
Process Control support in PHP implements the Unix style of process creation, program execution, signal handling and process termination. Process Control should not be enabled within a web server environment and unexpected results may happen if any Process Control functions are used within a web server environment.
½÷ÒԴ˾äÏ׸ø³¬¹¤£¬ÔÚweb server»·¾³Öв»ÒªÊ¹ÓÃÕâ×麯Êý£¬ÒòΪ»áµ¼Ö²»¿ÉÔ¤ÁϵĽá¹û¡£Áí£¬windows×÷Ϊ·ÇÀàunixϵͳ£¬Ã»ÓÐÕâЩº¯Êý¡£
PCNTLʹÓÃticksÀ´×÷ΪÐźŴ¦Àí»úÖÆ£¨signal handle callback mechanism£©£¬¿ÉÒÔ×îС³Ì¶ÈµØ½µµÍ´¦ÀíÒ첽ʼþʱµÄ¸ºÔØ¡£ºÎνticks£¿Tick ÊÇÒ»¸öÔÚ´úÂë¶ÎÖнâÊÍÆ÷ÿִÐÐ N ÌõµÍ¼¶Óï¾ä¾Í»á·¢ÉúµÄʼþ£¬Õâ¸ö´úÂë¶ÎÐèҪͨ¹ýdeclareÀ´Ö¸¶¨¡£
PCNTLµÄº¯Êý¶¼ÓÐÕâôЩ£º
ÐźŴ¦Àí
int pcntl_alarm ( int $seconds )
ÉèÖÃÒ»¸ö$secondsÃëºó·¢ËÍSIGALRMÐźŵļÆÊýÆ÷
bool pcntl_signal ( int $signo , callback $handler [, bool $restart_syscalls ] )
Ϊ$signoÉèÖÃÒ»¸ö´¦Àí¸ÃÐźŵĻص÷º¯Êý
ÏÂÃæÊÇÒ»¸ö¸ô5Ãë·¢ËÍÒ»¸öSIGALRMÐźţ¬²¢ÓÉsignal_handlerº¯Êý»ñÈ¡£¬È»ºó´òÓ¡Ò»¸ö“Caught SIGALRM”µÄÀý×Ó£º
view plaincopy to clipboardprint?
<?php
declare(ticks = 1);
function signal_handler($signal) {
print "Caught SIGALRM\n";
pcntl_alarm(5);
}
pcntl_signal(SIGALRM, "signal_handler", true);
pcntl_alarm(5);
for(;;) {
}
?>
<?php
declare(ticks = 1);
function signal_handler($signal) {
Ïà¹ØÎĵµ£º
PHPµÄÓŵãÊǼòµ¥ÊµÓá£ÓÃËüÀ´Ð´Ò»Ð©½Å±¾£¬»òÕßÊÇwebservice¡¢Êý¾Ý¿âÀàµÄһЩ·ÃÎÊ£¬È·ÊµÊǺܼòµ¥·½±ã¡£
µ«ËüÓÐÒ»¸öºÜ´óµÄÎÊÌ⣬¾ÍÊÇÄÚ´æµÄ»ØÊÕÎÊÌâ¡£¸ù¾ÝʹÓõľÑé¾õµÃÊǼ¸ºõÊÇûÓлØÊÕ¡£±ÈÈç½âÎöÒ»¸ö1°ÙÕ×µÄXMLÎļþ£¬ÄÚ´æʹÓÃÄܵ½1G¶à£¬¶øÇÒ»¹²»ÊÍ·Å¡£
ËùÒÔÓÃphpдºǫ́³ÌÐò£¬Ò»¶¨²»Òª×ö³ÉËÀÑ»·µÄ£¬ÖÁÉÙÊǹýÒ»¶Îʱ¼äÍ˳ö ......
ÔÚPHP±à³ÌÖÐ, ÎÒÃǾ³£»áÓöµ½Ò»Ð©Ö±½Ó²úÉúÊä³öµÄº¯Êý, Èçpassthru(),readfile(), var_dump() µÈ. µ«ÓÐʱÎÒÃÇÏë°ÑÕâЩº¯ÊýµÄÊä³öµ¼Èëµ½ÎļþÖÐ,»òÕßÏȾ¹ý´¦ÀíÔÙÊä³ö, »òÕß°ÑÕâЩº¯ÊýµÄÊä³ö×÷Ϊ×Ö·û´®À´´¦Àí.
¡¡¡¡ÕâʱÎÒÃǾÍÒªÓõ½ Output Buffer(Êä³ö»º³å) º¯ÊýÁË.
´¦ÀíÊä³ö»º³åµÄº¯ÊýÖ÷ÒªÓÐÕâô¼¸¸ö:
ob_start() ¿ªÊ¼Ê ......
×÷ΪʵÏÖ¶¯Ì¬ÍøÕ¾µÄ¹¤¾ßÖ®Ò»£¬PHPÒÔÆäÓï·¨¼òµ¥¡¢¸ßЧ¿ìËٺͶÔÊý¾Ý¿âµÄ¹ã·ºÖ§³Ö¶øÉîÊÜÓû§»¶Ó¡£±àдPHP³ÌÐòºÍASPÒ»ÑùÐèÒªÔÚ±¾»úµ÷ÊÔ£¬Îª´ËÐèÒªÅäÖÃһϵ÷ÊÔ»·¾³¡£
Óкܶ෽°¸¿ÉÒÔÑ¡Ôñ£¬ÕâÀïÌṩÁ½ÖÖ½ÏΪ¼òÒ׵ķ½·¨¡£
²»¹ÜÊÇÄÄÖÖ·½·¨£¬¶¼ÐèÒª°²×°PHP¡£Èç¹ûÄãÊÇPHPʹÓÃÕߣ¬Äã¿ÉÄÜÔÚÍøÉÏÕÒ¹ýPHPµÄ°²×°×ÊѶ£¬ËüÃǼ¸ºõ¶¼ËµµÄ ......
°²×°WAPMServ5.2.6ºó,ÓÃDreamweaver¿ÉÒÔ±àдºÍµ÷ÊÔPHP
Ê×ÏÈ£ºÒªÏÈÆôwapmserver,Æô¶¯ËùÓзþÎñ
È»ºó £ºÔÚDreamweaverÅäÖÃÕ¾µã£¬¾ßÌå²Ù×÷ÈçÏ£º
ÃèÊöϹؼüµÄ²½Ö裺
Ïȵý¨¸öÕ¾µã È»ºó
¸ß¼¶ Ñ¡Ï£º
·ÖÀࣺ±¾µØÐÅÏ¢
±¾µØ¸ùÎļþ¼Ð £¨Ñ¡ÔñPHPµÄ·¢²¼Îļþ¼Ð£©
Á´½ÓÏà¶ÔÓÚ Õ¾µã¸ùĿ¼
HTTPµØÖ· Http://localhost/
»º´æ Æ ......
ÏÖÔÚÎÒÃÇ¿ªÊ¼½éÉÜÐÂÎŵÄÁбíºÍɾ³ýÁË¡£
н¨Á¢Ò»¸öÎļþlistnews.php,ÄÚÈÝÈçÏ£º
< ?php
require_once('../inc/config.php');
//°üº¬ÅäÖÃÎļþ
?>
<html>
<head></head>
<title>ÐÂÎŹÜÀí</title>
<body>
<div class="newstitle"></div>
<div class="ne ......