×ðÁú¿­Ê±¹ÙÍøµÇ¼

̽ÌÖSwooleÒì²½±à³ÌÖеÄIOÐźŴ¦Àí

swooleÊÇÒ»¸öºÜÊ¢ÐеĻùÓÚphpÓïÑÔʵÏֵĸßÐÔÄÜÍøÂçͨѶ¿ò¼Ü£¬ËüÌṩÁËÖîÈçÒì²½io¡¢¶àÀú³Ì¡¢Ð­³ÌµÈ¹¦Ð§£¬¼«´óµÄÌáÉýÁË»ùÓÚphpÓïÑÔ¿ª·¢ÍøÂçÓ¦ÓóÌÐòµÄЧÂʺÍÐÔÄÜ¡£ÆäÖУ¬ioÐźŴ¦ÀíÊÇswooleÒì²½±à³ÌÖеÄÒ»¸öºÜÊÇÒªº¦µÄ²¿·Ö£¬±¾ÎľÍÀ´Ì½ÌÖÒ»ÏÂswooleÒì²½±à³ÌÖеÄioÐźŴ¦Àí¡£

Ò»¡¢IOÐźŴ¦ÀíµÄ¿´·¨

ÔÚÒ»Ñùƽ³£ÊÂÇéÖУ¬ÎÒÃǾ­³£ÐèÒª¼àÌýÀ´×ÔÖÖÖÖ×°±¸»òϵͳµÄÊäÈëÊä³öÐźÅ£¬Èç¶ÁдӲÅÌ»òÍøÂçÊý¾Ý¡¢ÎüÊÕ¼üÅÌ»òÊó±êÊäÈëµÈ¡£ÕâЩÐźŶ¼ÓпÉÄÜÒý·¢Ò»¸öÊÂÎñ£¬Òò´Ë£¬ÎÒÃÇÐèÒª½¨ÉèÒ»ÖÖIOÐźŴ¦Àí»úÖÆ£¬À´ÊµÏÖ¶ÔÕâЩÐźŵļàÌýºÍ´¦Àí¡£

IOÐźŴ¦ÀíÔÚUnix/Linux²Ù×÷ϵͳÉÏÊǷǾ­³£¼ûµÄ£¬ÎÒÃÇ¿ÉÒÔʹÓÃSIGIOÐźÅʵÏÖIOÐźŵĴ¦Àí¡£µ±Ò»¸öÎļþÐÎò·û(Èçsocket¡¢Îļþ¡¢¹ÜµÀµÈ)Éϱ¬·¢Á˿ɶÁ»ò¿ÉдÊÂÎñʱ£¬Äں˻áÏòÖ¸¶¨µÄÀú³Ì·¢ËÍSIGIOÐźÅ£¬¸æËßÀú³ÌÓÐÊý¾Ý¿É¶Á»òÊý¾Ý¿ÉдÁË¡£Òò´Ë£¬µ±ÎÒÃÇÏëҪʵÏÖÒì²½IO²Ù×÷ʱ£¬¾Í±ØÐèÏÈ´¦ÀíºÃIOÐźŵÄÏà¹ØÂß¼­¡£

¶þ¡¢SwooleÒì²½±à³ÌÖеÄIOÐźŴ¦Àí

ʹÓÃSwoole¿ò¼ÜÌṩµÄÒì²½IO¹¦Ð§£¬ÎÒÃÇ¿ÉÒÔÔÚPHPÓïÑÔÖкÜÀû±ãµÄ´¦ÀíIOÐźÅ¡£ÏÂÃ棬ÎÒÃÇÀ´ÏÈÈÝÒ»ÏÂSwooleÒì²½±à³ÌÖеÄIOÐźŴ¦Àí¡£

ÔÚSwooleÖмàÌýIOÊÂÎñ

SwooleµÄReactorÊÇÒ»¸öºÜÊǸßЧµÄ²¢·¢´¦ÀíÆ÷£¬ËüÖ§³ÖÒì²½IO¡¢×¼Ê±Æ÷¡¢ÐźżàÌýµÈ¶àÖÖ¹¦Ð§¡£ÎÒÃÇ¿ÉÒÔʹÓÃReactorÀ´¼àÌýIOÊÂÎñ¡£ÒÔÏÂÊǼàÌýsocker¿ÉдÊÂÎñµÄʾÀý´úÂ룺

<?php
$client = new SwooleClient(SWOOLE_SOCK_TCP);
$client->connect('127.0.0.1', 9501, 0.5);

SwooleEvent::add($client->sock, function($socket){
    echo "socket is writable
";
    SwooleEvent::del($socket);
});

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃSwooleClient½¨ÉèÒ»¸öTCP¿Í»§¶Ë£¬²¢ÊµÑéÅþÁ¬Ö¸¶¨µØµãºÍ¶Ë¿Ú¡£ÈôÊÇÅþÁ¬Àֳɣ¬ÄÇôÎÒÃǾͿÉÒÔÔÚReactorÖмÓÈë¸Ãsocket£¬²¢¼àÌý¿ÉдÊÂÎñ¡£µ±socket±äΪ¿Éд״̬ʱ£¬¾Í»á´¥·¢»Øµ÷º¯Êý£¬Êä³ö¡°socket is writable”µÄÐÅÏ¢¡£

SwooleÖеÄÐźŴ¦Àí

SwooleÌṩÁËSwooleProcess::signal()ÒªÁìÀ´ÉèÖÃÐźżàÌý¡£ÒÔÏÂÊÇÒ»¸ö×Ô½ç˵ÐźŴ¦Àíº¯ÊýµÄʾÀý£º

<?php
$worker = new SwooleProcess(function($worker){
    echo "worker is started
";

    SwooleProcess::signal(SIGTERM, function() use ($worker){
        echo "worker is stopped
";
        $worker->exit();
    });

    while(true){
        // do something
    }
});

$worker->start();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖУ¬ÎÒÃǽ¨ÉèÒ»¸ö×ÓÀú³Ì£¬²¢½«SIGTERMÐźŵĴ¦Àíº¯Êý½ç˵ΪÊä³ö¡°worker is stopped”£¬È»ºóÔÚÀú³ÌÑ­»·ÖÐÖ´ÐÐһЩ²Ù×÷¡£µ±ÊÕµ½SIGTERMÐźÅʱ£¬¾Í»á´¥·¢»Øµ÷º¯Êý£¬Êä³ö¡°worker is stopped”µÄÐÅÏ¢£¬²¢Í˳ö×ÓÀú³Ì¡£ÕâÑù¾Í¿ÉÒÔÔÚSwooleÖÐʵÏÖÀú³Ì¼äµÄͨѶºÍЭ×÷ÁË¡£

Èý¡¢½áÓï

IOÐźŴ¦ÀíÊÇSwooleÒì²½±à³ÌÖкÜÊÇÒªº¦µÄÒ»²¿·Ö£¬µ±ÎÒÃÇ´¦ÀíºÃIOÐźŵĴ¦ÀíÂß¼­£¬¾ÍÄܹ»Ô½·¢¸ßЧµØʵÏÖÍøÂçÓ¦ÓóÌÐò£¬ÌáÉýÐÔÄܺÍЧÂÊ¡£Í¨¹ýÉÏÊöʾÀý´úÂëµÄѧϰºÍʵ¼ù£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÕÆÎÕSwooleÖеÄIOÐźŴ¦ÀíÊÖÒÕ¡£

ÒÔÉϾÍÊÇ̽ÌÖSwooleÒì²½±à³ÌÖеÄIOÐźŴ¦ÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ