Swoole½ø½×£ºÊ¹ÓÃгÌÀ©Õ¹PHP²¢·¢´¦ÀíÄÜÁ¦
Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤£¬¹ØÓÚphpЧÀ͵ĸ߲¢·¢´¦ÀíÐèÇóÒ²Ô½À´Ô½Ç¿ÁÒ£¬ÓÈÆäÊÇÔÚwebÓ¦ÓóÌÐòÖС£¶øswooleгÌÕýÊÇÒ»¸öÇ¿Ê¢µÄÀ©Õ¹¿â£¬¿ÉÒÔ×ÊÖúphp¿ª·¢ÕßÇáËɵØʵÏָ߲¢·¢µÄ´¦Àí¡£
SwooleÊÇÒ»¿îCÓïÑÔ±àдµÄ³£×¤ÄÚ´æÐÍPHPг̿ò¼Ü£¬ËüÌṩÁ˸ßЧµÄ¶àÀú³Ì¡¢¶àÏ̡߳¢Òì²½IOµÈÌØÕ÷¡£SwooleµÄгÌģʽ¿ÉÒÔÈÃPHPÀú³Ì²¢·¢Ö´ÐУ¬ÎÞÐ轨ÉèÌØÁíÍâÏ̻߳òÀú³Ì£¬ÕâʹµÃÔÚ¿ÉÀ©Õ¹ÐÔºÍÐÔÄÜ·½Ãæ¾ùÓÐÁËÏÔÖøµÄÌáÉý¡£ÒÔÏÂΪSwooleг̵ÄÌص㣺
ʹÓÃгÌÈ¡´úỊ̈߳¬Ïû³ýÁËÏ̺߳ÍÀú³Ì½¨Éè¡¢Ïú»ÙµÄÏûºÄ£¬¹ÊЧÂÊÌá¸ßÊ®±¶ÒÔÉÏ¡£
Ö§³ÖÒì²½¡¢Ð³ÌºÍ´¿Í¬²½ÈýÖÖAPI£¬Àû±ãÓû§Æ¾Ö¤ÓªÒµÐèҪѡÔñ×î¼ÑµÄ´¦Àí·½·¨¡£
»ùÓÚHTTPºÍWebSocketÐÒé·â×°ÁËÍøÂç¿Í»§¶ËºÍЧÀͶˣ¬Àû±ãÓû§¿ª·¢ÍøÂçÓ¦Óá£
ʵÏÖÁ˵ײãµÄÒì²½IOͨѶ½á¹¹£¬°üÀ¨ÁËÊÂÎñÑ»·¡¢×¼Ê±Æ÷¡¢Îļþϵͳ¡¢ÍøÂçͨѶµÈ£¬ÔÚÍøÂçͨѶIOµÄÓ¦Óó¡¾°Öо߱¸ÏÔ×ÅÓÅÊÆ¡£
ÍêÈ«¼æÈÝPHP³£Óú¯ÊýºÍ¿ò¼Ü£¬Äܹ»¿ì½ÝµØǨáãPHPÏîÄ¿µ½Swooleг̰汾¡£
½ÓÏÂÀ´£¬±¾ÎĽ«´ÓSwooleг̵ÄʵÏÖÔÀí¡¢Ê¹ÓÃÒªÁìºÍÓÅÈõµãµÈ·½Ãæ¾ÙÐÐÏÈÈÝ¡£
Swooleг̵ÄʵÏÖÔÀí
µ±SwooleÆô¶¯Ð³Ìʱ£¬Ð³ÌµÄ״̬»á±»ÉúÑÄÔÚ¿ÍÕ»ÉÏ£¬ÕâʹµÃг̿ÉÒÔ¶Ô¸Ã״̬¾ÙÐÐÐ޸ģ¬²¢ÔÚÐëÒªµÄʱ¼ä»Ö¸´¸Ã״̬¡£µ±Ð³ÌÇл»Ê±£¬Swoole»á×Ô¶¯½«Ä¿½ñг̵Ä״̬´æ´¢ÔÚ¿ÍÕ»ÖУ¬È»ºóÇл»µ½ÏÂÒ»¸öг̡£µ±ÒÔºóÔÙ´ÎÇл»»Ø¸ÃгÌʱ£¬Swoole½«´Ó¿ÍÕ»Öлָ´¸Ãг̵Ä״̬£¬²¢¼ÌÐøÆäÖ´ÐС£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
±ðµÄ£¬Swooleг̿ÉÒÔÔÚÓöµ½IOÛÕ±Õʱ×Ô¶¯Èóö¿ØÖÆȨ£¬ÈÃÆäËûг̼ÌÐøÖ´ÐС£µ±IO²Ù×÷Íê³Éºó£¬Swoole»á»Ö¸´¸Ãг̵Ä״̬£¬²¢¼ÌÐøÖ´ÐС£ÕâÖÖ·½·¨±È½¨ÉèÏ̻߳òÀú³ÌÔ½·¢¸ßЧ£¬²¢ÇÒÆä×ÊÔ´ÏûºÄ¸üС£¬¿ÉÒÔÇáËɵØÓ¦¶Ô²¢·¢Á¿ÖØ´óµÄWebÓ¦Óá£
Swooleг̵ÄʹÓÃÒªÁì
Swooleг̵ÄʹÓ÷½·¨ºÜÊǼòÆÓ£¬Ö»Ðè×°ÖÃÏìÓ¦µÄSwooleÀ©Õ¹£¬²¢Ê¹ÓÃÏìÓ¦µÄAPI¼´¿ÉÕý³£Ê¹Óá£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄSwooleгÌʾÀý£º
<?php $server = new SwooleHttpServer('0.0.0.0', 9501); // ½¨ÉèÒ»¸öHTTP Server $server->on('request', function ($request, $response) { $response->header('Content-Type', 'text/plain'); $response->end("Hello World "); }); $server->start();
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëÌåÏÖ½¨ÉèÁËÒ»¸öHTTP Server£¬¼àÌýÔÚ9501¶Ë¿Ú£¬µ±ÓÐÇëÇó»á¼ûʱ·µ»Ø”Hello World”×Ö·û´®¡£ÒÔÉÏʾÀýÖУ¬SwooleµÄ$server->onÒªÁìÖ»ÐèÒª°ó¶¨requestÊÂÎñ¼´¿ÉʵÏÖ»ù±¾µÄHTTPЧÀÍ¡£Swoole¿ª·¢ÎĵµÖÐÌṩÁËÖÚ¶àµÄAPIºÍʾÀý£¬Àû±ãÓû§Æ¾Ö¤ÓªÒµÐèÒª¾ÙÐÐÏìÓ¦µÄ±àÂëºÍµ÷ÊÔ¡£
Swooleг̵ÄÓÅÈõµã
×÷Ϊһ¿îÇ¿Ê¢µÄ²¢·¢´¦Àí¿ò¼Ü£¬Swooleг̾ßÓÐÒÔÏÂÓŵ㣺
ÇáÁ¿¼¶£ºSwooleг̼«¶ËÇáÁ¿¼¶£¬²»ÐèÒª½¨ÉèÌØÁíÍâÏ̻߳òÀú³Ì¡£
¸ßЧÐÔ£ºSwooleгÌÄܹ»¸ßЧµØ´¦Àí´ó×ÚµÄHTTPÇëÇó£¬ÊµÏÖ²¢·¢´¦Àí¡£
¸ß¶È¿ÉÀ©Õ¹£ºSwooleгÌÖ§³ÖÒì²½¡¢Ð³ÌºÍ´¿Í¬²½ÈýÖÖAPI£¬ÌṩÁ˼«´óµÄÀ©Õ¹¿Õ¼äºÍÎÞаÐÔ¡£
Ò×ÓÃÐÔ£ºSwooleг̾ßÓи߶ÈÒ×ÓÃÐÔ£¬Óû§Ö»ÐèҪʹÓÃÏìÓ¦µÄAPI¼´¿ÉÇáËɵØʵÏÖÖØ´óµÄ²¢·¢´¦Àí¡£
ËäÈ»£¬SwooleгÌÒ²±£´æһЩÈõµã£º
¹ýʧ´¦ÀíÄÜÁ¦£ºSwooleг̵Ĺýʧ´¦ÀíÄÜÁ¦Ïà¶Ô½ÏÈõ£¬ÐèÒªÓû§ÔÚ±àÂëʱÃ÷È·×Ô¼ºµÄ¹ýʧ´¦Àí»úÖÆ¡£
ѧϰ±¾Ç®£ºSwooleг̵ÄÌØÕ÷ºÍAPIÏà¹ØÓÚͨÀýPHP¿ª·¢ÐèÒªÒ»¶¨µÄѧϰ±¾Ç®¡£
µ÷ÊÔÄѶȣºÓÉÓÚSwooleг̲»±£´æͨÀýµÄµ¥Ïß³Ìģʽ£¬Òò´Ëµ÷ÊÔÀú³Ì½ÏΪÄÑÌ⣬²¢ÐèÒª½èÖúµ×²ãµÄSwooleг̿â¾ÙÐиú×Ùµ÷ÊÔ¡£
½áÂÛ
×ÜÖ®£¬SwooleгÌÊÇPHP¿ª·¢Õß´¦Àí¸ß²¢·¢µÄ²»¶þ֮ѡ¡£Í¨¹ýÆäÇ¿Ê¢µÄгÌÔÀíºÍAPI£¬¿ÉÒÔʵÏÖ¸ßЧ¡¢Îȹ̵ÄWebЧÀÍ¡£ËäÈ»£¬ÔÚʹÓÃSwooleг̵ÄÀú³ÌÖУ¬ÐèҪעÖØÆäһЩȱÏݺÍÌØÕ÷£¬ÌØÊâÊǹýʧ´¦ÀíºÍµ÷ÊÔ·½Ãæ¡£²»¹ý£¬Ëæ×ÅSwooleг̵ÄÈÕÒæ³ÉÊìºÍÍêÉÆ£¬ÐÅÍÐÕâЩÎÊÌâÒ²»áÖð½¥»ñµÃ½â¾ö¡£
ÒÔÉϾÍÊÇSwoole½ø½×£ºÊ¹ÓÃгÌÀ©Õ¹PHP²¢·¢´¦ÀíÄÜÁ¦µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡