尊龙凯时人生就是博

SwooleʵÏÖ¸ßËÙMySQLÊðÀíЧÀÍÆ÷µÄ¹¹½¨ÒªÁì

Ëæ×Å»¥ÁªÍøÉú³¤µÄѸËÙ׳´ó£¬×ÔÁ¦¿ª·¢ÕߺÍÆóÒµÓû§¾­³£ÐèÒªÃæÁÙ´¦Àí´ó×ÚÊý¾ÝµÄʹÃü¡£mysqlÒѾ­³ÉΪÁË×î³£ÓõĹØϵÐÍÊý¾Ý¿âÖ®Ò»£¬Òò´Ë£¬ÎÒÃÇÐèÒªÌá¸ßÊý¾Ý¿âµÄ´¦ÀíЧÂʺÍÐÔÄÜ£¬¸ÄÉÆÓû§ÌåÑé¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃswooleʵÏÖ¸ßËÙmysqlÊðÀíЧÀÍÆ÷µÄ¹¹½¨ÒªÁ죬ÒÔÌá¸ßmysqlµÄÐÔÄÜ¡£

MySQLÊðÀíЧÀÍÆ÷¼ò½é

MySQLÊðÀíЧÀÍÆ÷ÊÇÒ»ÖÖ¿ÉÒÔͨ¹ý±à³Ì·½·¨»á¼ûMySQLÊý¾Ý¿âµÄ¹¤¾ß£¬Ëüͨ³£ÓÃÓÚЭµ÷¶à¸öÇëÇó¡¢»º´æÅÌÎÊЧ¹û¡¢ÔöÇ¿Çå¾²ÐԵȡ£Ê¹ÓÃMySQLÊðÀíЧÀÍÆ÷¿ÉÒÔ¸ÄÉÆÊý¾Ý¿âÐÔÄÜ£¬¼õÇáÊý¾Ý¿â¼ç¸º£¬Ìá¸ßÓû§ÌåÑé¡£

SwooleÏÈÈÝ

SwooleÊÇÒ»¸ö¸ßÐÔÄÜÒì²½ÍøÂçͨѶÒýÇ棬֧³ÖTCP¡¢UDP¡¢UnixµÄSocket´«Êäģʽ£¬Ò²Ö§³ÖHTTPºÍWebSocketЭÒ飬²¢ÇÒÖ§³ÖÒì²½MySQL¡¢RedisµÈ¹ØϵÐͺͷǹØϵÐÍÊý¾Ý¿â¡£Swoole»ùÓÚPHPÀ©Õ¹£¬Æäµ×²ãʹÓÃÁËepollºÍkqueueµÈ¸ßЧÊÂÎñÂÖѯ»úÖÆ£¬¿ÉÒÔ½èÖúÆäЭ³ÌÊÖÒÕ£¬ÒÔ·ÇÛÕ±Õ·½·¨Ö´ÐÐPHP´úÂ룬´ó´óÌá¸ßÁËI/O÷缯ÐÍʹÃüµÄ´¦ÀíЧÂÊ¡£

»ù±¾ÊµÏÖ˼Ð÷

¹¹½¨¸ßËÙMySQLÊðÀíЧÀÍÆ÷µÄ»ù±¾ÊµÏÖ˼Ð÷ÈçÏ£º

£¨1£©Ê¹ÓÃSwooleµÄÒì²½MySQL¿Í»§¶ËÅþÁ¬µ½MySQLЧÀÍÆ÷¡£

£¨2£©ÎüÊÕ¿Í»§¶ËÅþÁ¬£¬²¢½«¿Í»§¶Ë·¢Ë͵ÄÖ¸Áîת·¢¸øMySQLЧÀÍÆ÷¡£

£¨3£©ÔÚMySQLЧÀÍÆ÷·µ»ØÅÌÎÊЧ¹ûʱ£¬½«Ð§¹û»º´æµ½ÄÚ´æÖУ¬ÒÔ¼ÓËÙºóÐøµÄÅÌÎʲÙ×÷¡£

£¨4£©½«MySQLЧÀÍÆ÷·µ»ØµÄЧ¹û·¢Ë͸ø¿Í»§¶Ë¡£

£¨5£©¹Ø±ÕÅþÁ¬¡£

´úÂëʵÏÖ

ÒÔÏÂÊÇʹÓÃSwooleʵÏÖ¸ßËÙMySQLÊðÀíЧÀÍÆ÷µÄ´úÂ룺

<?php
$server = new SwooleServer("127.0.0.1", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$server->on("Connect", function($server, $fd){
    echo "Client connected.
";
});

$server->on("Receive", function($server, $fd, $from_id, $data){
    // ÅþÁ¬MySQL
    $mysql = new SwooleCoroutineMySQL();
    $mysql->connect([
        'host' => '127.0.0.1',
        'user' => 'root',
        'password' => '',
        'database' => 'test',
        'port' => 3306,
        'charset' => 'utf8mb4',
    ]);
    // Ö´ÐÐSQLÓï¾ä
    $result = $mysql->query($data);
    $server->send($fd, $result);
});

$server->on("Close", function($server, $fd){
    echo "Connection closed.
";
});

$server->start();

µÇ¼ºó¸´ÖÆ

×ܽá

±¾ÎÄÏÈÈÝÁËʹÓÃSwooleʵÏÖ¸ßËÙMySQLÊðÀíЧÀÍÆ÷µÄ¹¹½¨ÒªÁ죬¸ÃЧÀÍÆ÷¿ÉÌá¸ßMySQLÊý¾Ý¿âµÄÐÔÄÜ¡¢ÔöÇ¿Çå¾²ÐÔ¡¢¼õÇáÊý¾Ý¿â¼ç¸º¡¢¼ÓËÙÅÌÎÊ´¦ÀíµÈ¡£Ê¹ÓÃSwooleµÄЭ³ÌÊÖÒÕ£¬¿ÉÒÔ´ó´óÌá¸ßI/O÷缯ÐÍʹÃüµÄ²¢·¢´¦ÀíÄÜÁ¦£¬ÓÅ»¯´úÂëÐÔÄÜ¡£

¿ÉÊÇ£¬ÐèҪעÖصÄÊÇ£¬MySQLÊðÀíЧÀÍÆ÷ÐèÒª± £»¤ºÃ¿Í»§¶ËÊý¾Ý£¬ÁíÍ⣬ÐèҪ˼Á¿µ½¶àÖÖÒì³£ÇéÐεĴ¦Àí£¬ÈçÍøÂç²»Îȹ̡¢MySQLЧÀÍÆ÷ÅþÁ¬³¬Ê±¡¢ÅÌÎÊЧ¹ûÒì³£µÈµÈ¡£×îºÃÍŽá×Ô¼ºµÄÏÖÕæÏàÐξÙÐе÷½âºÍÐ޸ģ¬²Å»ªÊµÏÖÕæÕýµÄ¸ßËÙMySQLÊðÀíЧÀÍÆ÷¡£

ÒÔÉϾÍÊÇSwooleʵÏÖ¸ßËÙMySQLÊðÀíЧÀÍÆ÷µÄ¹¹½¨ÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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