尊龙凯时人生就是博

Swoole½ø½×£ºÊ¹ÓÃЭ³Ì¾ÙÐÐWebÅÀ³æ¿ª·¢

Ëæ×Å»¥ÁªÍøÊÖÒÕµÄÒ»Ö±Éú³¤ £¬webÅÀ³æÒѾ­³ÉΪµ±½ñ»¥ÁªÍøÓ¦Óò»¿É»òȱµÄÒ»²¿·Ö £¬ÆäÔÚÊý¾ÝÊÕÂÞ¡¢ÓªÒµ¾ò¿Í¡¢ÓßÇé¼à²âµÈ·½Ã涼ÓÐÆÕ±éµÄÓ¦Óó¡¾°¡£È»¶ø¹Å°åµÄwebÅÀ³æͨ³£Ê¹ÓöàÏ̻߳ò¶àÀú³ÌÀ´ÊµÏÖ²¢·¢ÇëÇó £¬ÃæÁÙµÄÎÊÌâ°üÀ¨ÉÏÏÂÎÄÇл»¿ªÏú¡¢ÄÚ´æÕ¼Óùý´óµÈ¡£¶ø½üÄêÀ´ £¬swoole³ÉΪphpÓ¦ÓÃÖеÄÒ»¿ÅÐÂÐÇ £¬ËüµÄЭ³ÌÌØÕ÷¿ÉÒÔΪwebÅÀ³æµÄ²¢·¢ÇëÇóÌṩ¸ßЧµÄ½â¾ö¼Æ»®¡£

ÔÚ±¾ÎÄÖÐ £¬½«ÏÈÈÝÔõÑùʹÓÃSwooleЭ³ÌʵÏÖÇáÁ¿¼¶¡¢¸ßЧµÄWebÅÀ³æ¡£

Swoole¼ò½é

SwooleÊÇ»ùÓÚPHPÓïÑÔʵÏֵĸßÐÔÄÜÍøÂçͨѶ¿ò¼Ü £¬Æä×î´óµÄÌصãÊÇÖ§³ÖЭ³Ì¡£Ð­³ÌÊÇÒ»ÖÖÓû§Ì¬µÄÇáÁ¿¼¶Ïß³Ì £¬Óë¹Å°åµÄÏ̺߳ÍÀú³ÌÏà±È £¬Ð­³ÌµÄÉÏÏÂÎÄÇл»¿ªÏúС¡¢ÄÚ´æÕ¼ÓÃÉÙ £¬¿ÉÒÔ¸üºÃµØÊ©Õ¹CPUµÄÐÔÄÜ¡£

ʹÓÃSwooleʵÏÖWebÅÀ³æ

SwooleµÄЭ³ÌÌØÕ÷ΪWebÅÀ³æµÄ¿ª·¢ÌṩÁËÒ»¸öºÜÊǺõÄƽ̨¡£¹Å°åµÄWebÅÀ³æÔÚ²¢·¢ÇëÇóʱÍùÍùÐèÒªÏûºÄ´ó×ÚµÄϵͳ×ÊÔ´ £¬¶øʹÓÃSwooleЭ³Ì¿ÉÒÔÇáËÉʵÏָ߲¢·¢ÇëÇó £¬Í¬Ê±»¹ÄÜ×èÖ¹¹Å°åµÄÏß³ÌÇл»´øÀ´µÄ¿ªÏú¡£

ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄʹÓÃSwooleʵÏÖµÄWebÅÀ³æʾÀý£º

<?php
// 1. ½¨ÉèSwoole HTTPЧÀÍÆ÷
$http = new SwooleHttpServer("0.0.0.0", 9501);

// 2. ´¦ÀíÇëÇó
$http->on('request', function ($request, $response) {
    // 3. ·¢ËÍHTTPÇëÇó
    $cli = new SwooleCoroutineHttpClient('www.www.zonelele.com', 80);
    $cli->setHeaders([
        'Host' => "www.www.zonelele.com",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);
    $cli->get('/');

    // 4. ÏìÓ¦HTMLÄÚÈÝ
    $response->header("Content-Type", "text/html; charset=utf-8");
    $response->end($cli->body);
});

// 5. Æô¶¯HTTPЧÀÍÆ÷
$http->start();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏʾÀý´úÂ뽨ÉèÁËÒ»¸öSwoole HTTPЧÀÍÆ÷ £¬¼àÌý¶Ë¿ÚºÅ9501¡£µ±ÓÐHTTPÇëÇóµÖ´ïʱ £¬Ð§ÀÍÆ÷½«·¢ËÍHTTPÇëÇóµ½°Ù¶ÈÍøÕ¾ £¬²¢ÏìÓ¦HTMLÄÚÈÝ¡£

SwooleЭ³ÌHTTP¿Í»§¶Ë

SwooleÌṩÁË»ùÓÚЭ³ÌµÄHTTP¿Í»§¶Ë £¬Í¨¹ýЭ³Ì¿ÉÒÔÔÚµ¥¸öÀú³ÌÄÚÀïͬʱÌᳫ¶à¸öHTTPÇëÇó £¬²¢ÐÐÖ´ÐÐÇëÇó £¬¶øÎÞÐ迪Æô¶à¸öÏ̻߳òÀú³Ì¡£

Э³ÌHTTP¿Í»§¶ËµÄʹÓúÜÊǼòÆÓ £¬ÒÔÏÂÊÇÒ»¸öʹÓÃʾÀý£º

<?php
// 1. ½¨ÉèЭ³ÌHTTP¿Í»§¶Ë
$cli = new SwooleCoroutineHttpClient('www.www.zonelele.com', 80);

// 2. ÉèÖÃÇëÇóÍ·
$cli->setHeaders([
    'Host' => "www.www.zonelele.com",
    "User-Agent" => 'Chrome/49.0.2587.3',
    'Accept' => 'text/html,application/xhtml+xml,application/xml',
    'Accept-Encoding' => 'gzip',
]);

// 3. ·¢ËÍHTTPÇëÇó
$cli->get('/');

// 4. Êä³öÏìÓ¦ÄÚÈÝ
echo $cli->body;

µÇ¼ºó¸´ÖÆ

ÒÔÉÏʾÀý´úÂ뽨ÉèÁËÒ»¸öЭ³ÌHTTP¿Í»§¶Ë £¬ÉèÖÃÇëÇóÍ·ºó·¢ËÍHTTPÇëÇó £¬²¢Êä³öÏìÓ¦ÄÚÈÝ¡£

ÔËÓÃЭ³ÌʵÏÖÅÀ³æÅÀÈ¡

ʹÓÃSwooleЭ³ÌHTTP¿Í»§¶Ë £¬ÎÒÃÇ¿ÉÒÔÇáËɵØʵÏÖ¸ßÐÔÄܵÄWebÅÀ³æ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃЭ³ÌʵÏÖµÄÅÀ³æʾÀý£º

<?php
// 1. ץȡ°Ù¶ÈËÑË÷Ч¹ûµÄÒ³Ãæ
$html = file_get_contents('https://www.www.zonelele.com/s?ie=UTF-8&wd=swoole');

// 2. ÆÊÎöHTML£¬ÌáÈ¡ËÑË÷Ч¹ûÁбíµÄURL
preg_match_all('/<a.*?href="(.*?)".*?>/is', $html, $matches);
$urls = $matches[1];

// 3. ²¢·¢ÇëÇóËÑË÷Ч¹ûÁбíµÄURL
$cli = new SwooleCoroutineHttpClient('www.www.zonelele.com', 80);
foreach ($urls as $url) {
    $cli->setHeaders([
        'Host' => "www.www.zonelele.com",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);
    $cli->get($url);
    echo $cli->body;
}

// 4. ¹Ø±ÕHTTP¿Í»§¶Ë
$cli->close();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏʾÀý´úÂëÊ×ÏÈץȡ°Ù¶ÈËÑË÷¡°swoole¡±Òªº¦×ÖµÄÒ³Ãæ £¬²¢ÆÊÎöHTML £¬ÌáÈ¡ËÑË÷Ч¹ûÁбíµÄURL £¬²¢²¢·¢ÇëÇóÕâЩURL¡£

×ܽá

Swoole×÷Ϊһ¸ö¸ßÐÔÄܵÄÍøÂçͨѶ¿ò¼Ü £¬ÆäЭ³ÌÌØÕ÷ΪWebÅÀ³æµÄ¿ª·¢ÌṩÁ˸ßЧµÄ½â¾ö¼Æ»®¡£Ê¹ÓÃSwooleЭ³ÌHTTP¿Í»§¶Ë £¬¿ÉÒÔ´ó·ùÌáÉýWebÅÀ³æµÄ²¢·¢ÇëÇóÄÜÁ¦ £¬Í¬Ê±×èÖ¹¶àÏ̻߳ò¶àÀú³Ì´øÀ´µÄ×ÊÔ´ÏûºÄºÍÉÏÏÂÎÄÇл»¿ªÏú¡£

ÒÔÉϾÍÊÇSwoole½ø½×£ºÊ¹ÓÃЭ³Ì¾ÙÐÐWebÅÀ³æ¿ª·¢µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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