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

SwooleʵÏÖ¸ßÐÔÄÜÒì²½ÍøÂç±à³ÌµÄÔ­ÀíÓëʵ¼ù

Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤ £¬¹ØÓÚÍøÂç±à³ÌµÄÐèÇóÒ²±äµÃÔ½À´Ô½¸ßЧ¡¢¸ßËÙ¡¢¸ß²¢·¢¡£ÎªÁËÖª×ãÕâЩÐèÇó £¬ÖÖÖÖÍøÂç±à³Ì¿ò¼ÜºÍÊÖÒÕÒ»Ö±Ó¿ÏÖ¡£ÆäÖÐ £¬swooleÊÇÒ»¿î»ùÓÚphpÓïÑԵĸßÐÔÄÜÒì²½ÍøÂçͨѶÒýÇæ¡£swooleͨ¹ýµ×²ãʵÏÖ¹ØÓÚ¿Í»§¶ËºÍЧÀͶ˵ÄÒ첽ͨѶ £¬¿ÉÒÔʵÏÖºÜÊǸßЧµÄÍøÂç±à³Ì¡£±¾ÎĽ«´ÓswooleʵÏÖÒì²½ÍøÂç±à³ÌµÄÔ­ÀíºÍʵ¼ùÁ½·½ÃæÀ´¾ÙÐÐÏÈÈÝ¡£

Ò»¡¢SwooleʵÏÖÒì²½ÍøÂç±à³ÌµÄÔ­Àí

ÔڹŰåµÄÛÕ±ÕʽÍøÂç±à³ÌÖÐ £¬µ±¿Í»§¶ËÓëЧÀÍÆ÷½¨ÉèÅþÁ¬ºó £¬¿Í»§¶ËÏòЧÀÍÆ÷·¢ËÍÇëÇó £¬È»ºóÔÚЧÀÍÆ÷ÏìӦ֮ǰ £¬¿Í»§¶Ë»áÒ»Ö±ÛÕ±ÕÔÚ·¢ËÍÇëÇóµÄ״̬¡£Õâ¸ö״̬Ï £¬ÎÞ·¨×öÆäËûµÄÊÂÇé £¬Òò´Ë²¢·¢ÐԺͿÉÀ©Õ¹ÐÔÊǺÜÊÇÈõµÄ¡£

Ïà¹ØÓÚÛÕ±ÕʽÍøÂç±à³Ì £¬Òì²½ÍøÂç±à³ÌÊÖÒÕʵÏÖ¸üΪ¸ßЧµØÖª×ã³ÌÐòÔ±¹ØÓÚ¸ßЧ¡¢¸ßËÙ¡¢¸ß²¢·¢µÄÐèÇó¡£SwooleÕýÊÇÒ»¸öÓÅÒìµÄÒì²½ÍøÂç±à³Ì¿ò¼Ü £¬ËüµÄʵÏÖÔ­ÀíÖ÷Òª°üÀ¨ÒÔϼ¸¸ö²¿·Ö£ºÊÂÎñÑ­»·¡¢Ð­³Ì¡¢·ÇÛÕ±ÕʽI/OºÍÐźŻúÖÆ¡£

ÊÂÎñÑ­»·£º

Swoole»á½¨ÉèÒ»¸öÊÂÎñÑ­»·¹¤¾ß £¬È»ºóͨ¹ý¼àÌý²î±ðµÄÊÂÎñÀ´¾ÙÐд¦Àí¡£ÕâЩÊÂÎñ¿ÉÄÜ°üÀ¨¿Í»§¶ËµÄÇëÇó¡¢Ð§ÀͶ˵ÄÏìÓ¦¡¢I/OµÄ¶ÁдµÈ¡£

Э³Ì£º

Swooleͨ¹ýЭ³Ì»úÖÆ £¬½ÓÄÉÀàËÆÓÚÇáÁ¿¼¶Ï̵߳ķ½·¨À´ÊµÏÖÒì²½·ÇÛÕ±ÕʽI/O¡£Ð­³Ì¿ÉÒÔ¿´×÷ÊÇÒ»ÖÖÇáÁ¿¼¶µÄÏß³Ì £¬ÊÇÔÚµ¥¸öÏß³ÌÖÐÔËÐв¢¾ÙÐÐÇл»µÄ¡£Í¨¹ýЭ³Ì £¬¿ÉÒÔʹµÃI/O²Ù×÷Äð³É·ÇÛÕ±ÕµÄ £¬´Ó¶øïÔÌ­ÆÚ´ýµÄʱ¼äºÍÌá¸ß³ÌÐòµÄÖ´ÐÐЧÂÊ¡£

·ÇÛÕ±ÕʽI/O£º

Swooleͨ¹ý·ÇÛÕ±ÕʽI/OÊÖÒÕʵÏÖÁËÒì²½¡¢ÊÂÎñÇý¶¯µÄÍøÂçͨѶ¡£ÔÚ·ÇÛÕ±ÕʽI/OÖÐ £¬²Ù×÷ϵͳÄں˲¢²»»áÆÚ´ýI/O²Ù×÷Íê³É £¬¶øÊÇÔÚI/O²Ù×÷»¹Ã»ÓÐÍê³Éʱֱ½Ó·µ»Ø £¬ÓɳÌÐò×ÔÐд¦Àí·µ»ØµÄЧ¹û¡£ÕâÖÖ·½·¨¿ÉÒÔ×èÖ¹ÔÚÆÚ´ýI/O²Ù×÷ʱÔì³ÉµÄ×ÊÔ´ÆÌÕÅ £¬ÒÔ¼°ÆÚ´ý²Ù×÷Íê³ÉËùÐèµÄʱ¼ä¡£

ÐźŻúÖÆ£º

Swooleͨ¹ýÐźŻúÖÆÀ´´¦Àí²Ù×÷ϵͳµÄÐźŠ£¬ÀýÈç׼ʱÆ÷ºÍÖÐÖ¹¡£ËüʹÓÃÁËLinuxϵͳµÄsignalfdÀ´¶ÁÈ¡ÎļþÐÎò·û £¬²¢ÔÚÊÂÎñÑ­»·ÖмàÌýÎļþÐÎò·ûÉϵÄÊÂÎñ¡£

ͨ¹ýÕâЩÊÖÒÕ £¬SwooleʵÏÖÁ˹ØÓÚ¿Í»§¶ËºÍЧÀͶ˵ÄÒ첽ͨѶ £¬´Ó¶ø¿ÉÒÔÓÐÓõØÌá¸ß³ÌÐòµÄЧÂʺͲ¢·¢ÐÔ¡£

¶þ¡¢SwooleʵÏÖÒì²½ÍøÂç±à³ÌµÄʵ¼ù

ÏàʶÁËSwooleʵÏÖÒì²½ÍøÂç±à³ÌµÄÔ­ÀíÖ®ºó £¬ÎÒÃÇÀ´¿´¿´Êµ¼ùÖÐÔõÑùʹÓÃSwooleÕâ¸öÇ¿Ê¢µÄÒì²½ÍøÂçͨѶÒýÇæ¡£ÏÂÃæÎÒÃǽ«Í¨¹ýÒ»¸ö¼òÆÓµÄÀý×ÓÀ´¾ÙÐÐÑÝʾ¡£

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃǽ«½¨ÉèÒ»¸ö¼òÆÓµÄWebЧÀÍÆ÷ £¬È»ºóʹÓÃSwooleÀ´¾ÙÐÐÒì²½´¦Àí¡£Ê×ÏÈ £¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öserver.phpÎļþ £¬ÓÃÀ´Æô¶¯Ð§ÀÍÆ÷£º

<?php

$server = new SwooleHttpServer("0.0.0.0", 9501);

$server->set([
    'worker_num' => 2,
    'dispatch_mode' => 1,
]);

$server->on('request', function ($request, $response) {
    $response->header('Content-Type', 'text/plain');
    $response->end("Hello World
");
});

$server->start();

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÎļþÖÐ £¬ÎÒÃÇÊ×ÏȽ¨ÉèÁËÒ»¸öSwooleµÄHTTPЧÀÍÆ÷¡£È»ºó £¬Í¨¹ýŲÓÃsetÒªÁìÀ´ÉèÖÃЧÀÍÆ÷µÄһЩÉèÖòÎÊý £¬ÀýÈçÊÂÇéÀú³ÌÊýÄ¿ºÍµ÷Àíģʽ¡£½Ó×Å £¬ÎÒÃÇÉèÖÃÁËÒ»¸ö»Øµ÷º¯Êý £¬Õâ¸öº¯Êý»áÔÚÎüÊÕµ½¿Í»§¶ËÇëÇóʱ±»Å²Óá£ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃÇÖ»ÊǼòÆӵطµ»ØÁËÒ»¸ö×Ö·û´®¡°Hello World¡±¡£×îºó £¬ÎÒÃÇͨ¹ýŲÓÃstartÒªÁìÀ´Æô¶¯Ð§ÀÍÆ÷¡£

½ÓÏÂÀ´ £¬ÎÒÃÇÐèÒªÔÚÏÂÁîÐÐÖÐÀ´Æô¶¯Õâ¸öЧÀÍÆ÷£º

php server.php

µÇ¼ºó¸´ÖÆ

ÔÚЧÀÍÆ÷Æô¶¯Ö®ºó £¬ÎÒÃÇ¿ÉÒÔʹÓÃcurlÏÂÁîÀ´¾ÙÐлá¼û£º

curl http://localhost:9501

µÇ¼ºó¸´ÖÆ

Äã»á·¢Ã÷ £¬Õû¸öÇëÇóºÍÏìÓ¦µÄÀú³ÌÊǷdz£¿ìËÙµÄ £¬ÓÉÓÚSwooleʵÏÖÁËÒ첽ͨѶ £¬´Ó¶ø×èÖ¹ÁËÛÕ±ÕʽÍøÂç±à³ÌÖпÉÄÜ·ºÆðµÄÍøÂçÑÓ³Ù¡£

³ýÁËÉÏÊöµÄ¼òÆÓÀý×ÓÖ®Íâ £¬Swoole»¹¿ÉÒÔÓÃÀ´ÊµÏÖÖÖÖÖÖØ´óµÄÍøÂç±à³Ì¹¦Ð§¡£ÀýÈç £¬¿ÉÒÔÓÃÀ´ÊµÏָ߲¢·¢µÄWebЧÀÍÆ÷¡¢WebSocketЧÀÍÆ÷¡¢TCPЧÀÍÆ÷¡¢UDPЧÀÍÆ÷µÈµÈ¡£±ðµÄ £¬Swoole»¹¿ÉÒÔºÍÖîÈçMySQL¡¢RedisµÈÆäËûµÄÊý¾Ý¿â»ººÍ´æ×é¼þÅäºÏʹÓà £¬´Ó¶øʵÏÖ¸üΪÖØ´óµÄÍøÂç±à³ÌÐèÇó¡£

×ܽ᣺

±¾ÎÄͨ¹ýÏÈÈÝSwooleʵÏÖÒì²½ÍøÂç±à³ÌµÄÔ­ÀíºÍʵ¼ù £¬Ïò¸÷ÈËչʾÁËSwooleµÄÇ¿Ê¢¹¦Ð§ºÍ¸ßЧÐÔÄÜ¡£Í¨¹ýÏàʶSwooleµÄµ×²ãʵÏÖÔ­ÀíºÍ±à³Ìʵ¼ù £¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÓ¦ÓÃSwooleÀ´ÊµÏÖ¸ßЧ¡¢¸ßËÙ¡¢¸ß²¢·¢µÄÍøÂç±à³Ì¡£Í¬Ê± £¬Swoole»¹¿ÉÒÔºÍÆäËûµÄÊý¾Ý¿â»ººÍ´æ×é¼þÅäºÏʹÓà £¬´Ó¶øÖª×ãÖÖÖÖÖØ´óµÄÍøÂç±à³ÌÐèÇó¡£ÐÅÍÐËæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤ £¬SwooleÕâÖÖ¸ßÐÔÄÜÒì²½ÍøÂçͨѶÒýÇ潫ÔÚδÀ´»ñµÃÔ½·¢ÆÕ±éµÄÓ¦Óá£

ÒÔÉϾÍÊÇSwooleʵÏÖ¸ßÐÔÄÜÒì²½ÍøÂç±à³ÌµÄÔ­ÀíÓëʵ¼ùµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ