尊龙凯时人生就是博

Э³Ì±à³ÌÓëSwooleÊÃ÷ÈÕ½£ºÊµÏָ߲¢·¢½Ó¿ÚÉè¼Æ

Ëæ×Å»¥ÁªÍøÓ¦ÓõÄÆÕ¼°£¬Ô½À´Ô½¶àµÄÓ¦ÓÃÐèÒªÃæÁٸ߲¢·¢µÄÌôÕ½¡£¹Å°åµÄÏ̳߳ػòÀú³Ì³Ø·½·¨ÒѾ­²»¿ÉÖª×ãÕâÖÖÇéÐÎϵÄÐèÇó¡£Ð­³Ì±à³ÌÊÖÒÕ³ÉΪÁËÒ»ÖÖ½â¾ö¸ß²¢·¢ÎÊÌâµÄÓÐÓ÷½·¨£¬¶øswooleÔòÊÇÏÖÔÚÓ¦ÓÃ×îÆÕ±éµÄЭ³Ì¿ò¼ÜÖ®Ò»¡£

±¾ÎĽ«ÏÈÈÝЭ³Ì±à³ÌµÄ»ù±¾¿´·¨ºÍÔ­Àí£¬ÒÔ¼°ÔõÑùʹÓÃSwoole¿ò¼Ü¾ÙÐи߲¢·¢½Ó¿ÚÉè¼Æ¡£ÎÒÃǽ«ÒÔÒ»¸ö¼òÆÓµÄWebЧÀÍΪÀý£¬·Ö°ì·¨ÏÈÈÝÔõÑùʹÓÃЭ³ÌºÍSwooleʵÏָ߲¢·¢µÄ½Ó¿ÚÉè¼Æ¡£

Ò»¡¢Ð­³Ì±à³Ì¼ò½é

Э³ÌÊÇÖ¸Ò»ÖÖ»ùÓÚÓû§Ì¬µÄÇáÁ¿¼¶Ị̈߳¬ÔÚÀú³Ì»òÏß³ÌÖÐʵÏÖµÄÒ»ÖÖЭ×÷ʽ¶àʹÃü´¦Àí·½·¨¡£ÓëÏß³ÌÏà±È£¬Ð­³ÌµÄ×ÊÔ´ÏûºÄ¸üÉÙ£¬Çл»ÉÏÏÂÎĵļÛÇ®¸üС¡£Í¨¹ýʹÓÃЭ³Ì£¬¿ÉÒÔ¸üºÃµØʹÓÃ×ÊÔ´£¬Ìá¸ß³ÌÐòµÄÔËÐÐЧÂÊ¡£

Э³Ì±à³ÌµÄ»ùÀ´Ô´ÀíÊÇ£¬ÔËÐÐÔÚͳһ¸öÏß³ÌÄڵĶà¸öЭ³ÌÖ®¼ä²¢·¢Ö´ÐУ¬Í¨¹ýЭ³ÌµÄ¹ÒÆðºÍ»Ö¸´»úÖÆʵÏÖ´úÂëµÄÁ÷³Ì¿ØÖÆ¡£Ð­³ÌÖ®¼äµÄÇл»²»ÐèÒª½øÈëÄÚºË̬£¬¶øÊÇÔÚÓû§Ì¬Íê³É£¬Òò´ËÇл»·Ç³£¿ìËÙ£¬Äܹ»Öª×ã¸ß²¢·¢µÄÐèÇó¡£

¶þ¡¢Swoole¼ò½é

SwooleÊÇÒ»¿î»ùÓÚЭ³ÌµÄÍøÂçͨѶ¿ò¼Ü£¬ËüÌṩÁ˶ÔTCP/UDP/WebSocketµÈЭÒéµÄÖ§³Ö£¬²¢ÌṩÁ˶àÖÖÒì²½±à³ÌÄ£×Ó£¬ÈçЭ³Ì¡¢Òì²½IOµÈ£¬Äܹ»Öª×ãÖÖÖָ߲¢·¢³¡¾°µÄÐèÇó¡£

SwooleµÄÖ÷ÒªÌصã°üÀ¨ÒÔϼ¸µã£º

»ùÓÚЭ³ÌµÄÍøÂçͨѶģ×Ó£¬ÎÞÐ轨Éè´ó×ÚµÄÏ̺߳ÍÀú³Ì£¬Äܹ»¸üºÃµØʹÓÃ×ÊÔ´¡£

ÌṩÁË»ùÓÚÒì²½±à³ÌÄ£×ӵĶàÖÖAPI£¬ÈçÒì²½MySQL¡¢RedisµÈ¡£

Ö§³Ö¶àÀú³Ìģʽ£¬Äܹ»³ä·ÖʹÓöàºËCPUµÄÓÅÊÆ¡£

ÌṩÁ˶àÖָ߲¢·¢½â¾ö¼Æ»®£¬ÈçTCP³¤ÅþÁ¬¡¢ÅþÁ¬³ØµÈ¡£

ÄÚÖÃÁËHTTPЧÀÍÆ÷£¬¿ÉÖ±½ÓÓÃÓÚWeb¿ª·¢¡£

Èý¡¢½Ó¿ÚÉè¼ÆÓëʵÏÖ

¼ÙÉèÎÒÃÇÓÐÒ»¸öÐèÒª´¦Àí´ó×ÚHTTPÇëÇóµÄ½Ó¿Ú£¬ÎÒÃÇÏ£ÍûÄܹ»ÔÚ´¦ÀíÇëÇóʱʵÏָ߲¢·¢ºÍÐÔÄܵÄÌáÉý¡£½ÓÏÂÀ´£¬ÎÒÃÇÒÔ´ËΪÀý£¬·Ö°ì·¨ÏÈÈÝÔõÑùʹÓÃЭ³ÌºÍSwooleʵÏָ߲¢·¢µÄ½Ó¿ÚÉè¼Æ¡£

½¨ÉèHTTPЧÀÍÆ÷

Ê×ÏÈ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öHTTPЧÀÍÆ÷£¬ÒÔÎüÊÕ¿Í»§¶ËµÄHTTPÇëÇó¡£Ê¹ÓÃSwoole¿ò¼Ü¿ÉÒÔºÜÊÇÀû±ãµØʵÏÖÈçÏ´úÂ룺

$http = new swoole_http_server("0.0.0.0", 9501);

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

$http->start();

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃǽ¨ÉèÁËÒ»¸öHTTPЧÀÍÆ÷£¬²¢¼àÌý9501¶Ë¿Ú¡£µ±ÎüÊÕµ½¿Í»§¶ËÇëÇóʱ£¬»áÖ´ÐÐonRequest»Øµ÷º¯Êý£¬²¢·¢ËÍÒ»¸ö”Hello World”µÄÏìÓ¦ÐÂÎÅ¡£

Ìí¼ÓЭ³ÌÖ§³Ö

½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª¸øHTTPЧÀÍÆ÷Ìí¼ÓЭ³ÌÖ§³Ö¡£ÔÚSwooleÖУ¬¿ÉÒÔʹÓÃЭ³Ì¿Í»§¶ËÀ´Ìæ»»¹Å°åµÄͬ²½¿Í»§¶Ë£¬´Ó¶øʵÏÖЭ³ÌµÄÒì²½±à³Ì¡£

$http = new swoole_http_server("0.0.0.0", 9501);

$http->on('request', function ($request, $response) {
    $redis = new SwooleCoroutineRedis();
    $mysql = new SwooleCoroutineMySQL();

    $redis->connect('127.0.0.1', 6379);
    $mysql->connect([
        'host' => '127.0.0.1',
        'user' => 'root',
        'password' => '',
        'database' => 'test',
    ]);

    $redis->set('key', 'value');
    $mysql->query("SELECT * FROM `table` WHERE `id` = 1");

    $response->header("Content-Type", "text/plain");
    $response->end("Hello World
");
});

$http->set([
    'enable_coroutine' => true,
]);

$http->start();

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÌí¼ÓÁËRedisºÍMySQLµÄЭ³Ì¿Í»§¶Ë£¬²¢ÔÚÇëÇó´¦ÀíÖÐʹÓÃÕâЩЭ³Ì¿Í»§¶Ë¡£ÔÚÆô¶¯HTTPЧÀÍÆ÷µÄʱ¼ä£¬ÎÒÃÇÐèÒªÉèÖÃenable_coroutineÑ¡ÏîΪtrueÀ´¿ªÆôЭ³ÌÖ§³Ö¡£

Ìí¼ÓÅþÁ¬³ØÖ§³Ö

ΪÁ˸üºÃµØÖÎÀíÅþÁ¬£¬ÎÒÃÇ¿ÉÒÔʹÓÃÅþÁ¬³ØÊÖÒÕÀ´Ìá¸ß×ÊÔ´µÄʹÓÃÂʺÍÐÔÄÜÌåÏÖ¡£SwooleÄÚÖÃÁ˶àÖÖÅþÁ¬³ØµÄÖ§³Ö£¬ÈçMySQLºÍRedisÅþÁ¬³Ø¡£ÏÂÃæÊÇÒ»¸öʹÓÃSwooleÄÚÖõÄMySQLÅþÁ¬³ØµÄʾÀý´úÂ룺

$http = new swoole_http_server("0.0.0.0", 9501);

$http->on('request', function ($request, $response) {
    $pool = SwooleDatabasePDOPool::class;
    $options = [
        'dsn' => 'mysql:host=127.0.0.1;dbname=test',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8mb4',
    ];

    /** @var SwooleDatabasePDOProxy $db */
    $db = SwooleDatabase::getInstance($pool)->getConnection();
    $db->query("SELECT * FROM `table` WHERE `id` = 1");
    $db->close();

    $response->header("Content-Type", "text/plain");
    $response->end("Hello World
");
});

$http->start();

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁËSwooleÄÚÖõÄMySQLÅþÁ¬³Ø£¬²¢Í¨¹ýgetInstanceÒªÁì»ñÈ¡µ½Ò»¸öÅþÁ¬¡£ÔÚʹÓÃÍê±Ïºó£¬ÎÒÃÇÐèÒªÊÖ¶¯¹Ø±Õ¸ÃÅþÁ¬¡£ÅþÁ¬³ØµÄʹÓÿÉÒÔÓÐÓõØïÔÌ­ÅþÁ¬½¨ÉèºÍÏú»ÙµÄ¿ªÏú£¬´Ó¶øÌá¸ßÓ¦ÓÃÐÔÄÜ¡£

ËÄ¡¢×ܽá

ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËЭ³Ì±à³ÌºÍSwoole¿ò¼Ü£¬²¢Í¨¹ýÒ»¸ö¼òÆÓµÄWebЧÀ͵ÄʾÀý£¬ÐðÊöÁËÔõÑùʹÓÃЭ³Ì±à³ÌºÍSwoole¿ò¼ÜʵÏָ߲¢·¢½Ó¿ÚÉè¼Æ¡£

Э³Ì±à³ÌÊÇÒ»ÖÖ¸ßЧµÄ±à³Ì·½·¨£¬Äܹ»ÓÐÓõØÌá¸ßÓ¦ÓõÄÐÔÄܺÍÍÌÍÂÁ¿¡£SwooleÔòÊÇÏÖÔÚ½ÏÁ¿Ê¢ÐеÄЭ³Ì¿ò¼Ü£¬ÌṩÁ˶àÖÖÒì²½±à³ÌÄ£×Ӻ͸߲¢·¢½â¾ö¼Æ»®£¬Äܹ»Öª×ãÖÖÖָ߲¢·¢³¡¾°µÄÐèÇó¡£

¹ØÓÚÐèÒª´¦Àí´ó×ÚÇëÇóµÄÓ¦Óã¬Ê¹ÓÃЭ³Ì±à³ÌºÍSwoole¿ò¼Ü¿ÉÒÔ×ÊÖúÎÒÃǸüºÃµØ½â¾ö¸ß²¢·¢ÎÊÌ⣬Ìá¸ßÓ¦ÓõÄÐÔÄܺÍÎȹÌÐÔ¡£

ÒÔÉϾÍÊÇЭ³Ì±à³ÌÓëSwooleÊÃ÷ÈÕ½£ºÊµÏָ߲¢·¢½Ó¿ÚÉè¼ÆµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ