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

Swoole½ø½×£ºÔõÑùʹÓÃЭ³ÌʵÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷

Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤£¬ÍøÂçÇëÇó±äµÃÔ½À´Ô½ÆµÈÔºÍÖØ´ó£¬ÔõÑùʵÏÖ¸ßЧµÄ²¢·¢Êý¾Ý²Ù×÷ÒѾ­³ÉΪЧÀÍÆ÷¿ª·¢ÕßÃæÁÙµÄÒ»¸öÖ÷ÒªÎÊÌâ¡£ÔڹŰåµÄphp¿ª·¢ÖУ¬ÎªÁËʵÏÖ²¢·¢²Ù×÷£¬ÍùÍùÐèÒª½ÓÄɶàÀú³Ì»ò¶àÏ̵߳ķ½·¨£¬µ«ÕâÖÖ·½·¨±£´æ×ÅÏÔÖøµÄÐÔÄÜÆ¿¾±ºÍ×ÊÔ´ÆÌÕÅ¡£È»¶ø£¬ÔÚʹÓÃswooleЭ³ÌÖ®ºó£¬¿ª·¢Õß¿ÉÒÔÇáËɵØʵÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷£¬±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃswooleЭ³ÌʵÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷¡£

Ò»¡¢Ê²Ã´ÊÇSwooleЭ³Ì

SwooleÊÇ»ùÓÚPHPÓïÑÔµÄÍøÂçͨѶ¿ò¼Ü£¬ËüÄÚÖÃÁËЭ³ÌÖ§³Ö£¬¿ÉÒÔ×ÊÖú¿ª·¢ÕßÇáËɵØʵÏÖ¸ßЧµÄÒì²½±à³ÌºÍ²¢·¢²Ù×÷¡£Ð­³ÌÊÇÒ»ÖÖÇáÁ¿¼¶µÄỊ̈߳¬¿ÉÒÔʵÏÖÔÚÒ»¸öÏß³ÌÖÐÔÚ²î±ðµÄ´úÂë¿éÖ®¼ä¾ÙÐÐÇл»£¬Òò´Ë¿ÉÒÔÔÚµ¥Ïß³ÌÏÂÃæʵÏÖ²¢·¢²Ù×÷¡£SwooleµÄЭ³ÌÄ£¿éÖ÷ÒªÓÐÒÔϼ¸¸ö×é¼þ£º

1¡¢Ð­³Ìµ÷ÀíÆ÷£ºÓÃÓÚЭ³Ì¿ØÖƺÍÇл»¡£

2¡¢Ð­³Ì¿Í»§¶Ë£º¿ÉÒÔʵÏÖЭ³Ì·½·¨ÏµÄÍøÂçͨѶ¡£

3¡¢Ð­³ÌÐźż°×¼Ê±Æ÷£º¿ÉÒÔʵÏÖЭ³Ì·½·¨ÏµÄ׼ʱÆ÷ºÍÐźŴ¦Àí¡£

4¡¢Ð­³ÌSocket¼°HTTPЧÀÍÆ÷£º¿ÉÒÔʵÏÖЭ³Ì·½·¨ÏµÄSocketͨѶºÍHTTPЧÀÍÆ÷¡£

¶þ¡¢Ê¹ÓÃSwooleЭ³ÌʵÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷

ÔÚSwooleЭ³ÌÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃCoun()º¯ÊýÀ´½¨ÉèÒ»¸öЭ³Ì£¬ÀýÈ磺

Coun(function(){
    // do something in coroutine
});

µÇ¼ºó¸´ÖÆ

ÔÚЭ³ÌÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃSwooleÌṩµÄЭ³ÌMySQL¿Í»§¶ËºÍЭ³ÌRedis¿Í»§¶ËÀ´ÊµÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷¡£ÏÂÃæÎÒÃǽ«ÏêϸÏÈÈÝʹÓÃÕâÁ½ÖÖ¿Í»§¶ËµÄÒªÁì¡£

1¡¢Ê¹ÓÃЭ³ÌMySQL¿Í»§¶Ë

ÔÚʹÓÃЭ³ÌMySQL¿Í»§¶Ë֮ǰ£¬ÎÒÃÇÐèÒªÏÈ×°ÖÃswooleÀ©Õ¹ÖеÄmysqlÄ£¿é£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°Öãº

pecl install swoole_mysql

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³ÉÖ®ºó£¬ÎÒÃǾͿÉÒÔÔÚЭ³ÌÖÐʹÓÃЭ³ÌMySQL¿Í»§¶ËÁË¡£ÏÂÃæÊÇÒ»¸öʹÓÃЭ³ÌMySQL¿Í»§¶ËÅÌÎÊÊý¾ÝµÄÀý×Ó£º

Coun(function(){
    $db = new SwooleCoroutineMySQL();
    $db->connect([
        'host' => '127.0.0.1',
        'port' => 3306,
        'user' => 'root',
        'password' => '123456',
        'database' => 'test',
    ]);
    $res = $db->query('select * from user');
    var_dump($res);
});

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÊ×ÏȽ¨ÉèÁËÒ»¸öЭ³ÌMySQL¿Í»§¶Ë£¬È»ºóʹÓÃconnect()ÒªÁìÅþÁ¬µ½MySQLЧÀÍÆ÷¡£½Ó×Å£¬ÎÒÃÇʹÓÃquery()ÒªÁìÀ´Ö´ÐÐÒ»ÌõÅÌÎÊÓï¾ä£¬²¢½«Ð§¹û·ÅÈë$res±äÁ¿ÖС£ÕâÑù£¬ÎÒÃǾͿÉÒÔÔÚЭ³ÌÖÐʵÏÖ¸ßЧµÄÊý¾ÝÅÌÎÊÁË¡£

2¡¢Ê¹ÓÃЭ³ÌRedis¿Í»§¶Ë

ÔÚʹÓÃЭ³ÌRedis¿Í»§¶Ë֮ǰ£¬ÎÒÃÇͬÑùÐèÒªÏÈ×°ÖÃswooleÀ©Õ¹ÖеÄredisÄ£¿é£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî×°Öãº

pecl install swoole_redis

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³ÉÖ®ºó£¬ÎÒÃǾͿÉÒÔÔÚЭ³ÌÖÐʹÓÃЭ³ÌRedis¿Í»§¶ËÁË¡£ÏÂÃæÊÇÒ»¸öʹÓÃЭ³ÌRedis¿Í»§¶Ë´æÈ¡Êý¾ÝµÄÀý×Ó£º

Coun(function(){
    $redis = new SwooleCoroutineRedis();
    $redis->connect('127.0.0.1', 6379);
    $redis->set('name', 'swoole');
    $name = $redis->get('name');
    var_dump($name);
});

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÊ×ÏȽ¨ÉèÁËÒ»¸öЭ³ÌRedis¿Í»§¶Ë£¬È»ºóʹÓÃconnect()ÒªÁìÅþÁ¬µ½RedisЧÀÍÆ÷¡£½Ó×Å£¬ÎÒÃÇʹÓÃset()ÒªÁ콫һ¸ö¼üÖµ¶Ô´æÈëRedisÖУ¬ÔÙʹÓÃget()ÒªÁìÀ´»ñÈ¡¼üÖµ¶ÔµÄÖµ¡£ÕâÑù£¬ÎÒÃǾͿÉÒÔÔÚЭ³ÌÖÐʵÏÖ¸ßЧµÄ´æÈ¡Êý¾ÝÁË¡£

Èý¡¢×ܽá

ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÏÈÈÝÁËÔõÑùʹÓÃSwooleЭ³ÌÀ´ÊµÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷¡£Í¨¹ýʹÓÃЭ³ÌMySQL¿Í»§¶ËºÍЭ³ÌRedis¿Í»§¶Ë£¬ÎÒÃÇ¿ÉÒÔÔÚÒ»¸öÏß³ÌÖÐʵÏÖ¸ßЧµÄÊý¾ÝÅÌÎʺͲÙ×÷¡£Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤£¬Ê¹ÓÃSwooleЭ³ÌÀ´ÊµÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷ÒѾ­³ÉΪЧÀÍÆ÷¿ª·¢ÕßµÄÒ»¸öÖ÷ÒªÊÖÒÕ¡£ÎÒÃÇÏ£Íû±¾ÎÄÄܹ»¶Ô¸÷ÈËÓÐËù×ÊÖú£¬×ÊÖú¸÷È˸üºÃµØÓ¦¶Ô²¢·¢Êý¾Ý²Ù×÷µÄÎÊÌâ¡£

ÒÔÉϾÍÊÇSwoole½ø½×£ºÔõÑùʹÓÃЭ³ÌʵÏÖ¸ßЧ²¢·¢Êý¾Ý²Ù×÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ