»ùÓÚSwoole¹¹½¨¸ßÐÔÄܵÄÊÓƵµã²¥ÏµÍ³
½üÄêÀ´£¬ÊÓƵµã²¥Æ½Ì¨ÏñÓêºó´ºËñ°ãÓ¿ÏÖ£¬²»ÉÙÆóÒµ¡¢»ú¹¹¡¢Ð¡ÎÒ˽È˶¼½«ÏßÉÏÊÓƵЧÀÍÄÉÈë×Ô¼ºµÄÓªÒµÖС£¶øÒªÏëÓµÓÐÓÅÒìµÄÊÓƵµã²¥Æ½Ì¨£¬¸ßÐÔÄܾÍÊÇÆäÖÐÒ»¸ö±Ø²»¿ÉÉÙµÄÒªËØ¡£±¾ÎĽ«Ì½ÌÖÔõÑù»ùÓÚswoole¹¹½¨¸ßÐÔÄܵÄÊÓƵµã²¥ÏµÍ³¡£
Ò»¡¢SwooleÏÈÈÝ
SwooleÊÇÒ»¿î»ùÓÚPHPÓïÑÔ¿ª·¢µÄÒì²½¡¢¸ßÐÔÄÜÍøÂçͨѶ¿ò¼Ü£¬ËüÖ§³ÖTCP/UDP¡¢HTTP¡¢WebSocketµÈ¶àÖÖͨѶÐÒ飬²¢ÇÒÌṩÁËÒì²½ÎļþIO¡¢¶àÀú³Ì¡¢Ð³Ì¡¢×¼Ê±Æ÷µÈ³¬Ç¿µÄ¹¦Ð§¡£
SwooleÄܹ»³ä·ÖʹÓÃCPUºÍÄÚ´æ×ÊÔ´£¬Í¨¹ýÒì²½ºÍгÌÊÖÒÕ£¬ÓÐÓõØïÔÌÁËÏß³ÌÇл»ºÍÄڴ濪Ïú£¬Í¬Ê±Ìá¸ßÁ˲¢·¢´¦ÀíÄÜÁ¦£¬°ü¹ÜÁËϵͳµÄ¸ßÐÔÄÜ£¬Òò´Ë£¬Ô½À´Ô½¶àµÄÆóÒµ×îÏȽÓÄÉSwooleÀ´¹¹½¨¸ßÐÔÄܵÄÍøÂçЧÀÍ¡£
¶þ¡¢ÊÓƵµã²¥ÏµÍ³µÄ¼Ü¹¹Éè¼Æ
1.Á÷ýÌåЧÀÍ
ÔÚÊÓƵµã²¥ÏµÍ³ÖУ¬Á÷ýÌåЧÀÍÊÇÒ»¸ö×î½¹µãµÄЧÀÍ£¬ÈÏÕæÊÓƵÎļþµÄÉÏ´«¡¢´æ´¢¡¢×ªÂë¡¢¼ÓÃܵÈһϵÁвÙ×÷¡£ÎªÁËÈ·±£Á÷ýÌåЧÀ͵ĸ߿ÉÓÃÐÔ£¬¿ÉÒÔ½ÓÄɼ¯ÈºÄ£Ê½£¬¼´½«¶à¸öÁ÷ýÌåЧÀÍÆ÷×é³ÉÒ»¸ö¼¯Èº¡£
2.WebЧÀÍÆ÷
ÔÚWebЧÀÍÆ÷ÉÏ£¬Ö÷ÒªÌṩÕë¶ÔÓû§µÄÇ°¶ËÒ³ÃæºÍAPI½Ó¿ÚЧÀÍ¡£Óû§¿ÉÒÔͨ¹ýWeb½çÃæ¾ÙÐÐÊÓƵ²¥·Å¡¢ËÑË÷¡¢¹ºÖá¢Õ˺ÅÖÎÀíµÈ²Ù×÷£¬ÔÚÆäÖУ¬Óû§ÇëÇóµÄ²¢·¢Á¿½Ï´ó£¬Òò´ËÐèÒª°ü¹ÜWebЧÀÍÆ÷µÄ¸ßÐÔÄÜ¡£
WebЧÀÍÆ÷¿ÉÒÔ½ÓÄÉNginx»òApacheµÈЧÀÍÆ÷£¬µ«ÒÔNginxΪÀý£¬¿ÉÒÔʹÓÃËüµÄ·´ÏòÊðÀí¹¦Ð§£¬½«Óû§µÄÇëÇóת·¢¸øºó¶ËµÄÊÓƵЧÀÍ¡£
3.»º´æЧÀÍ
ÔÚÁ÷ýÌåЧÀÍ¡¢WebЧÀÍÆ÷ÖУ¬¶¼ÐèҪʹÓõ½»º´æЧÀÍ£¬ÒÔÌá¸ßÊý¾ÝµÄ¶ÁÈ¡ËÙÂʺÍÏìӦʱ¼ä¡£ÓÉÓÚÊÓƵµã²¥ÏµÍ³ÖпÉÄܻᱣ´æ´ó×ڵĻº´æÊý¾Ý£¬Òò´ËÐèÒª½ÓÄɸßÐÔÄÜ¡¢µÍÑӳٵĻº´æЧÀÍ¡£Ò»¸ö³£¼ûµÄÑ¡ÔñÊÇʹÓÃRedisÀ´×÷Ϊ»º´æЧÀÍ£¬Í¨¹ýRedisµÄ»º´æÊÖÒÕ£¬Äܹ»´ó´óÌá¸ßϵͳµÄÐÔÄÜ¡£
Èý¡¢SwooleÔÚÊÓƵµã²¥ÏµÍ³ÖеÄÓ¦ÓÃ
1.ʹÓÃSwoole×÷ΪHTTPЧÀÍÆ÷
ÔÚWebЧÀÍÆ÷ÖУ¬³£¼ûµÄ×ö·¨ÊÇʹÓÃNginx»òApacheµÈЧÀÍÆ÷£¬µ«ÕâЩЧÀÍÆ÷¹ØÓڸ߲¢·¢µÄÇëÇó´¦ÀíÄÜÁ¦ÓÐËùÏÞÖÆ¡£¶øSwooleÌṩÁ˸ßÐÔÄܵÄHTTPЧÀÍÆ÷£¬¿ÉÒÔ½«ÇëÇóµÄÏìӦʱ¼äïÔ̵½ºÁÃ뼶±ð£¬²¢ÇÒ¿ÉÒÔÖ§³ÖIPv6¡¢SSL¼ÓÃÜ¡¢HTTP/2µÈÐÒé¡£
ͬʱ£¬SwooleµÄгÌÊÖÒÕÒ²Äܹ»ÓÐÓõؽµµÍϵͳµÄ¿ªÏú£¬ÌáÉýÐÔÄÜ¡£ÔÚSwooleÖУ¬Í¨¹ý½¨Éèг̣¬¿ÉÒÔÈöà¸öÇëÇóÖ®¼äÏ໥ÆÚ´ý£¬Í¬Ê±²¢·¢Ö´Ðжà¸öʹÃü£¬´Ó¶ø¸üºÃµØʹÓÃϵͳ×ÊÔ´¡£
2.ʹÓÃSwoole×÷ΪTCP/UDPЧÀÍÆ÷
ÔÚÊÓƵµã²¥ÏµÍ³ÖУ¬TCP/UDPͨѶҲÊǺÜÊÇÖ÷ÒªµÄ£¬ÀýÈçʹÓÃTCPÐÒé¾ÙÐÐÓû§µÄÑéÖ¤¡¢Ê¹ÓÃUDPÐÒé¾ÙÐÐÊÓƵÁ÷µÄ´«ÊäµÈ¡£¶øSwooleÌṩÁ˸ßÐÔÄÜ¡¢Ö§³Ö¶àÀú³ÌµÄTCP/UDPЧÀÍÆ÷£¬¿ÉÒÔÀû±ãµØÖ§³ÖTCP/UDPͨѶ¡£
ÔÚSwooleµÄTCP/UDPЧÀÍÆ÷ÖУ¬¿ÉÒÔʹÓÃÒì²½ºÍгÌÊÖÒÕÀ´Ìá¸ßÐÔÄÜ£¬Í¬Ê±Ö§³Ö×Ô½ç˵ÐæźÍÊý¾Ý°üÆÊÎö£¬Öª×ã²î±ðµÄÓªÒµÐèÇó¡£
3.ʹÓÃSwoole×÷ΪWebSocketЧÀÍÆ÷
WebSocketÊÇÒ»ÖÖ»ùÓÚTCPÐÒéµÄÐÒ飬Ëü¿ÉÒÔÔÚ¿Í»§¶ËºÍЧÀÍÆ÷Ö®¼ä¾ÙÐÐË«ÏòͨѶ£¬ÊÊÓÃÓÚʵʱͨѶ³¡¾°£¬ÀýÈçÔÚÏßÖ±²¥¡¢ÔÚÏß¾Û»á»áÒéµÈ¡£ÔÚÊÓƵµã²¥ÏµÍ³ÖУ¬Ê¹ÓÃWebSocket¿ÉÒÔÌṩ¸üºÃµÄÓû§ÌåÑé¡£
¶øSwooleÌṩÁ˸ßÐÔÄÜ¡¢Ö§³Ö¶àÀú³ÌµÄWebSocketЧÀÍÆ÷£¬¿ÉÒÔÀû±ãµØÖ§³ÖWebSocketͨѶ£¬Í¬Ê±¿ÉÒÔʹÓÃSwooleµÄг̺ÍÒì²½ÊÖÒÕÀ´Ìá¸ßÐÔÄܺͲ¢·¢´¦ÀíÄÜÁ¦¡£
ËÄ¡¢×ܽá
ͨ¹ýÉÏÊöµÄÏÈÈÝ£¬¿ÉÒÔ¿´³öSwooleÔÚÊÓƵµã²¥ÏµÍ³ÖеÄÓ¦ÓúÜÊÇÆձ飬¿ÉÒÔ¼«´óµØÌá¸ßϵͳµÄÐÔÄܺÍÏìÓ¦ËÙÂÊ£¬Í¬Ê±Ò²ÌṩÁ˸»ºñµÄ¹¦Ð§Ö§³Ö£¬ÎªÆóÒµ¡¢»ú¹¹¡¢Ð¡ÎÒ˽È˵ÈÓû§Ìṩ¸üºÃµÄÓû§ÌåÑé¡£
Òò´Ë£¬¹ØÓÚÒª¹¹½¨¸ßÐÔÄܵÄÊÓƵµã²¥ÏµÍ³µÄ¿ª·¢ÕßÀ´Ëµ£¬SwooleÊÇÒ»¸öºÜÊÇÖµµÃ˼Á¿µÄÑ¡Ôñ¡£ËäÈ»£¬ÔÚʹÓÃSwooleµÄÀú³ÌÖУ¬»¹ÐèҪͨ¹ýÓÅ»¯´úÂë¡¢Ìá¸ßЧÀÍÆ÷µÄÓ²¼þÉèÖõȷ½·¨½øÒ»²½Ìá¸ßϵͳµÄÐÔÄÜ¡£
ÒÔÉϾÍÊÇ»ùÓÚSwoole¹¹½¨¸ßÐÔÄܵÄÊÓƵµã²¥ÏµÍ³µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡