尊龙凯时人生就是搏

Swoole½ø½×£ºÔõÑùʹÓÃЭ³Ì¾ÙÐи߲¢·¢Êý¾Ý´¦Àí

ÔÚÏÖ´ú»¥ÁªÍøÓ¦ÓÃÖУ¬¸ß²¢·¢ÒѾ­³ÉΪÁËÒ»¸ö²»¿É×èÖ¹µÄÎÊÌâ¡£¶øÕë¶Ô¸ß²¢·¢µÄ½â¾ö¼Æ»®ÖУ¬Ð­³ÌÊÖÒÕÊÇÒ»¸ö±¸ÊÜÍÆÐíµÄÆ«Ïò¡£ÔÚphpÁìÓòÄÚ£¬swoole¾ÍÊÇÒ»¿îЭ³Ì¿ò¼Ü£¬¿ÉÒÔÓÃÀ´ÊµÏָ߲¢·¢µÄÊý¾Ý´¦Àí¡£

±¾ÎĽ«ÏÈÏÈÈÝSwooleµÄЭ³ÌÌØÕ÷£¬È»ºóÕë¶ÔÊý¾Ý´¦ÀíµÄ³¡¾°£¬ÏêϸÐðÊöSwooleÖÐЭ³ÌµÄʹÓÃÒªÁì¼°×¢Öصã¡£

Ò»¡¢SwooleЭ³Ì

SwooleÊÇÒ»¿î»ùÓÚPHPÓïÑÔµÄЭ³Ì¿ò¼Ü¡£SwooleµÄЭ³Ì¿ÉÒÔÔÚͳһÏß³ÌÄÚʵÏÖ²¢·¢Ö´ÐУ¬×èÖ¹Á˽øÈëÄÚºË̬ºÍÓû§Ì¬µÄƵÈÔÇл»£¬ÌáÉýÁË´¦ÀíЧÂÊ¡£Í¬Ê±£¬ÔÚЭ³ÌÄÚ²¿£¬IO²Ù×÷²»ÔÙ¼ûµ¼ÖÂÏ̵߳ÄÛÕ±Õ£¬Ê¹µÃÓ¦ÓÃÄܹ»Ôڸ߲¢·¢Ï¼á³Ö½Ï¸ßµÄÍÌÍÂÁ¿¡£

Э³ÌÊÇÒ»ÖÖ½ÏÁ¿ÌØÊâµÄº¯Êý¡£ÔÚЭ³ÌÄÚ£¬¿ÉÒÔÖ´ÐÐÒ»¶Î´úÂ룬Ȼºó½«Ö´ÐÐȨ½»»Ø¸øŲÓ÷½£¬ÆÚ´ýÏÂÒ»´ÎŲÓÃʱÔÙ¼ÌÐøÖ´ÐС£Ò²¾ÍÊÇ˵£¬Ð­³ÌÄÚ²¿¿ÉÒÔʵÏÖÔÝÍ£ºÍ»Ö¸´£¬ÕâʹµÃЭ³Ì¿ÉÒÔÓÃÀ´ÊµÏÖÒì²½±à³Ì¡£

¶þ¡¢ÔõÑùÔÚSwooleÖÐʹÓÃЭ³Ì¾ÙÐи߲¢·¢Êý¾Ý´¦Àí

Êý¾Ý¿â²Ù×÷

ÔڹŰåµÄPHPÓ¦ÓÃÖУ¬¾ÙÐÐÊý¾Ý¿â²Ù×÷ʱ£¬ÎÒÃǾ­³£Ê¹ÓõÄÊÇͬ²½µÄ·½·¨£¬¼´·¢ËÍÒ»¸öÇëÇóºóÐèÒªÆÚ´ýÏìÓ¦²Å»ª¾ÙÐÐÏÂÒ»ÐдúÂëµÄÖ´ÐС£¶øÔÚSwooleÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃЭ³ÌÖеÄÒì²½·½·¨£¬À´ÊµÏָ߲¢·¢µÄÊý¾Ý´¦Àí¡£

ÒÔÏÂÊÇSwooleÖÐʹÓÃЭ³Ì¾ÙÐÐÊý¾Ý¿â²Ù×÷µÄʾÀý´úÂ룺

// ½¨ÉèMySQLЭ³Ì¿Í»§¶Ë
$db = new SwooleCoroutineMySQL();

// ÅþÁ¬MySQLЧÀÍÆ÷
$db->connect([
    'host' => '127.0.0.1',
    'user' => 'root',
    'password' => 'root',
    'database' => 'test',
]);

// ÔÚЭ³ÌÖÐÖ´ÐÐÅÌÎʲÙ×÷
SwooleCoroutineun(function() use($db){
    $result = $db->query('select * from users');
    // ´¦ÀíÅÌÎÊЧ¹û
});

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÊ×ÏÈͨ¹ý SwooleCoroutineMySQL() ½¨ÉèÁËÒ»¸öMySQLЭ³Ì¿Í»§¶Ë£¬²¢Ê¹Óà connect() ÒªÁìÅþÁ¬µ½MySQLЧÀÍÆ÷¡£È»ºó£¬ÎÒÃÇÔÚ SwooleCoroutineun() Э³ÌÖУ¬Ê¹Óà $db->query() Ö´ÐÐÁËÒ»ÌõÅÌÎÊÓï¾ä£¬²¢Í¨¹ý $result »ñÈ¡ÁËÅÌÎÊЧ¹û¡£

HTTPÇëÇó

¹ØÓÚHTTPÇëÇóµÄ´¦Àí£¬SwooleÖÐÌṩÁËÒ»¸ö SwooleCoroutineHttpClient() ×é¼þ¡£Í¬ÑùµØ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÕâ¸ö×é¼þÀ´ÊµÏÖÒì²½´¦Àí£¬ÒԴ˵ִï¸ß²¢·¢µÄÄ¿µÄ¡£

ÒÔÏÂÊÇʹÓà SwooleCoroutineHttpClient() ¾ÙÐÐHTTPÇëÇóµÄʾÀý´úÂ룺

// ½¨ÉèHTTP¿Í»§¶Ë
$client = new SwooleCoroutineHttpClient('www.www.zuhaoqu.com', 80);

// ÔÚЭ³ÌÖÐÖ´ÐÐÇëÇó²Ù×÷
SwooleCoroutineun(function() use($client){
    $client->get('/');
    // ´¦ÀíÏìÓ¦
});

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖУ¬ÎÒÃǽ¨ÉèÁËÒ»¸öHTTP¿Í»§¶Ë£¬È»ºóÔÚ SwooleCoroutineun() Э³ÌÖУ¬Í¨¹ý $client ÌᳫÁËÒ»´ÎGETÇëÇ󣬲¢Í¨¹ýÏìӦЧ¹û¾ÙÐкóÐø´¦Àí¡£

Redis²Ù×÷

×îºó£¬ÎÒÃÇÀ´ÏÈÈÝÒ»ÏÂʹÓÃЭ³Ì¾ÙÐÐRedis²Ù×÷µÄÒªÁì¡£SwooleÖÐÌṩÁËÒ»¸ö SwooleCoroutineRedis() ×é¼þ£¬¿ÉÓÃÓڸ߲¢·¢µÄRedis²Ù×÷¡£

ÒÔÏÂÊÇSwooleʹÓÃЭ³Ì¾ÙÐÐRedis²Ù×÷µÄʾÀý´úÂ룺

// ½¨ÉèRedisЭ³Ì¿Í»§¶Ë
$redis = new SwooleCoroutineRedis();

// ÅþÁ¬RedisЧÀÍÆ÷
$redis->connect('127.0.0.1', 6379);

// ÔÚЭ³ÌÖÐÖ´ÐвÙ×÷
SwooleCoroutineun(function() use($redis){
    $redis->set('key', 'value');
    $result = $redis->get('key');
    // ´¦ÀíÅÌÎÊЧ¹û
});

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊöʾÀý´úÂëÖУ¬ÎÒÃÇÊ×ÏÈͨ¹ý SwooleCoroutineRedis() ½¨ÉèÁËÒ»¸öRedisЭ³Ì¿Í»§¶Ë£¬²¢Ê¹Óà connect() ÒªÁìÅþÁ¬µ½RedisЧÀÍÆ÷¡£È»ºó£¬ÎÒÃÇÔÚ SwooleCoroutineun() Э³ÌÖУ¬Ê¹Óà $redis->set() ÒªÁìÉèÖÃÁËÒ»¸ö¼üÖµ¶Ô£¬²¢Í¨¹ý $redis->get() »ñÈ¡Á˸üüÖµ¶Ô£¬×îºóͨ¹ý $result ±äÁ¿»ñÈ¡ÁËÅÌÎÊЧ¹û¡£

Èý¡¢×¢ÖØÊÂÏî

Ö»¹ÜʹÓÃÁËЭ³ÌÊÖÒÕ£¬SwooleÖоÙÐи߲¢·¢Êý¾Ý´¦ÀíÈÔÈ»ÐèҪעÖØһЩÊÂÏî¡£

Ê×ÏÈ£¬ÓÉÓÚSwooleÖÐЭ³Ì¹¦Ð§ÊÇÓÉЭ³Ìµ÷ÀíÆ÷À´µ÷ÀíµÄ£¬ÒÔÊÇÎÒÃÇÔÚʹÓÃЭ³ÌʱÐèÒª×ñÕÕһЩԼÊø¡£ÀýÈ磬Э³ÌÖв»¿É¾ÙÐÐÛÕ±ÕIO²Ù×÷£¬²»È»»áµ¼ÖÂÏ̵߳ÄÛÕ±Õ£¬½ø¶øÓ°ÏìÕû¸öÓ¦ÓõÄÐÔÄÜ¡£±ðµÄ£¬¹ØÓÚ´ó×ÚCPU÷缯Ð͵IJÙ×÷£¬Ò²ÐèÒªÉóÉ÷ʹÓÃЭ³Ì£¬ÒÔÃâÕ¼Óùý¶àµÄ×ÊÔ´¡£

Æä´Î£¬¹ØÓÚÊý¾Ý¿â¡¢RedisµÈ³¤ÅþÁ¬Ð§À͵IJÙ×÷£¬ÔÚ¾ÙÐÐÅþÁ¬³ØÖÎÀíʱ£¬ÐèÒªÉèÖÃÒ»¶¨µÄ³¬Ê±Ê±¼ä£¬×èÖ¹ÅþÁ¬¹ý¶à»ò¹ýÉÙ£¬Ó°ÏìÓ¦ÓõÄÎȹÌÐÔºÍÐÔÄÜ¡£

×îºó£¬SwooleЭ³ÌµÄʹÓÃÐèҪרÐÄÉóÉ÷¡£ËäȻЭ³Ì¿ÉÒÔÌá¸ßÓ¦ÓõÄÐÔÄÜ£¬µ«ÈôÊÇʹÓò»µ±£¬Ò²»áµ¼Ö±àдµÄ´úÂëÄÑÒÔÃ÷È·ºÍµ÷ÊÔ¡£

ËÄ¡¢×ܽá

±¾ÎÄÏêϸÏÈÈÝÁËÔÚSwoole¿ò¼ÜÖÐÔõÑùʹÓÃЭ³ÌÊÖÒÕ¾ÙÐи߲¢·¢Êý¾Ý´¦Àí¡£ÎÒÃÇͨ¹ýʵÀýչʾÁËÔõÑùʹÓÃSwooleÖеÄMySQLЭ³Ì¿Í»§¶Ë¡¢HTTP¿Í»§¶Ë¡¢RedisЭ³Ì¿Í»§¶ËµÈ×é¼þ¡£Í¬Ê±£¬Ò²ÏÈÈÝÁËÔõÑùÔÚЭ³ÌʹÓÃʱÐèҪעÖصÄÎÊÌâ¡£

ÔÚSwooleµÄÌìÏÂÀЭ³ÌÒѾ­³ÉΪÁËʵÏָ߲¢·¢Êý¾Ý´¦ÀíµÄÖ÷ÒªÊֶΡ£ÎÒÃÇÐÅÍУ¬Í¨¹ýÕÆÎÕSwooleЭ³ÌµÄʹÓÃÒªÁìºÍ×¢ÖØÊÂÏÄú¿ÉÒÔ¸üºÃµØÓ¦¶ÔÓªÒµÖеĸ߲¢·¢ÎÊÌâ¡£

ÒÔÉϾÍÊÇSwoole½ø½×£ºÔõÑùʹÓÃЭ³Ì¾ÙÐи߲¢·¢Êý¾Ý´¦ÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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