Swooleʵ¼ù£ºÊ¹ÓÃг̾ÙÐи߲¢·¢Êý¾ÝÆÊÎö
Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÉú³¤£¬´ó×ÚµÄÊý¾ÝÐèÒª±»ÆÊÎöºÍ´¦Àí¡£ÌØÊâÊÇÔÚ»¥ÁªÍø½ðÈÚ¡¢Òƶ¯Ö§¸¶µÈÐÐÒµ£¬¸ß²¢·¢µÄÊý¾ÝÆÊÎö±äµÃÔ½À´Ô½Ö÷Òª¡£¶øswoole×÷Ϊһ¿î¸ßÐÔÄܵÄphpÍøÂçͨѶÒýÇ棬ÆäгÌÌØÕ÷¿ÉÒÔÓÅ»¯phpµÄ´¦ÀíЧÂÊ£¬½ø¶øÌáÉýÊý¾ÝÆÊÎöµÄЧÂÊ¡£±¾ÎĽ«ÏÈÈÝʹÓÃswooleг̾ÙÐи߲¢·¢Êý¾ÝÆÊÎöµÄʵ¼ù¡£
ʲôÊÇSwooleг̣¿
SwooleÊÇÒ»¿î¸ßÐÔÄܵÄPHPÍøÂçͨѶÒýÇ棬ÆäÖ§³ÖгÌÌØÕ÷¡£Ð³ÌÊÇÒ»ÖÖÓû§Ì¬µÄÇáÁ¿¼¶Ị̈߳¬ÆäÔËÐÐÔÚͳһ¸öÀú³ÌÖУ¬Õ¼ÓÃÉÙÉÙµÄϵͳ×ÊÔ´¡£Óë¹Å°å¶àÏ̷߳½·¨²î±ðµÄÊÇ£¬Ð³Ì¿ÉÒÔÔÚ²»Çл»Ï̵߳ÄÇéÐÎÏÂʵÏÖ¶àʹÃü£¬Òò´ËʹÓÃг̿ÉÒÔʵÏָ߲¢·¢¡¢¸ßÐÔÄܵÄÍøÂçͨѶ´¦Àí¡£
Swooleг̵ÄÓÅÊÆ
Ïà¹ØÓڹŰåµÄ¶àÀú³ÌºÍ¶àÏß³ÌÊÖÒÕ£¬Swooleг̾ßÓÐÒÔÏÂÓÅÊÆ£º
2.1 ½ÚԼϵͳ×ÊÔ´£ºÐ³ÌÔËÐÐÔÚͳһ¸öÀú³ÌÖУ¬ÏûºÄµÄϵͳ×ÊÔ´Ïà¶Ô½ÏÉÙ¡£
2.2 ½µµÍCPU¸ºÔØ£º¹Å°åµÄ¶àÏ̴߳¦Àí·½·¨»áÔöÌíCPUµÄ¸ºÔØ£¬½µµÍÕûÌåÐÔÄÜ£¬¶øг̿ÉÒÔÔÚÒ»¸öÏß³ÌÄÚʵÏÖ¶àʹÃü£¬ïÔÌCPU¸ºÔØ¡£
2.3 ÔöÌí³ÌÐòÏìÓ¦ËÙÂÊ£ºÊ¹ÓÃг̿ÉÒÔïÔÌÏß³ÌÇл»µÄʱ¼ä£¬Ìá¸ß³ÌÐòÏìÓ¦ËÙÂÊ¡£
2.4 ¼ò»¯³ÌÐòÉè¼Æ£º¹Å°åµÄ¶àÏ̳߳ÌÐòÉè¼ÆÐèÒª¹Ø×¢Ïß³ÌÖ®¼äµÄͬ²½ºÍ»¥³â£¬¶øг̲»ÐèÒªÕâÑùµÄÖØ´ó´¦Àí£¬Ê¹ÓÃÆðÀ´Ô½·¢¼òÆÓ¡£
ʹÓÃSwooleг̾ÙÐи߲¢·¢Êý¾ÝÆÊÎöµÄʵÏÖ
ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃSwooleгÌʵÏָ߲¢·¢Êý¾ÝÆÊÎö¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄÊý¾ÝÆÊÎöʾÀý£º
function parseData($data) { $result = []; $lines = explode(PHP_EOL, $data); foreach ($lines as $line) { $fields = explode(',', $line); $temp = []; foreach ($fields as $field) { $temp[] = trim($field); } $result[] = $temp; } return $result; } go(function () { $data = file_get_contents('data.csv'); $result = parseData($data); var_dump($result); });
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃÇʹÓÃÁËSwooleµÄgoº¯ÊýÀ´ÊµÏÖг̡£ÔÚгÌÖУ¬ÎÒÃÇÊ×ÏȶÁÈ¡CSVÃûÌõÄÊý¾Ý£¬²¢Å²ÓÃparseDataº¯Êý¾ÙÐÐÆÊÎö¡£parseDataº¯Êý»á½«Êý¾Ý°´ÐÐÖ§½â£¬²¢°´¶ººÅÖ§½â×ֶΣ¬×îÖÕ·µ»ØÒ»¸ö¶þάÊý×é¡£×îºó£¬ÔÚгÌÖдòÓ¡ÆÊÎöЧ¹û¡£
×ܽá
±¾ÎÄÏÈÈÝÁËSwooleг̵ÄÌØÕ÷ºÍÓÅÊÆ£¬ÒÔ¼°Ê¹ÓÃSwooleг̾ÙÐи߲¢·¢Êý¾ÝÆÊÎöµÄʵ¼ù¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ¿ÉÒÔ³ä·ÖʹÓÃSwooleг̵ÄÌØÕ÷£¬ÓÅ»¯³ÌÐòÐÔÄÜ£¬Ìá¸ßÊý¾ÝÆÊÎöЧÂÊ¡£Í¬Ê±£¬SwooleµÄÎĵµºÍÉçÇøÒ²ºÜÊǸ»ºñ£¬¿ÉÒÔΪÎÒÃǵĿª·¢ÌṩÓÅÒìµÄÖ§³ÖºÍ×ÊÖú¡£
ÒÔÉϾÍÊÇSwooleʵ¼ù£ºÊ¹ÓÃг̾ÙÐи߲¢·¢Êý¾ÝÆÊÎöµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡