1

こんにちは、私はこのスクリプトでウェブサイト (SHOP) を解析しています:

<?php
date_default_timezone_set('Europe/Warsaw');
ini_set('memory_limit', '-1');
set_time_limit(120);
require_once '../../../simple_html_dom.php';    
require_once'../../../functions.php';
echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8">';
echo "Beginning import at: ".date('H').":".date('i')."\n";
mysql_connect ("localhost","xxxx","xxxx"); 
mysql_select_db ("sklepy"); 
mysql_query('SET CHARSET utf8'); 
$sklepy=(mysql_query("SELECT * FROM `ps_supplier` where id_supplier = 3"));
do {
$curl = curl_init();
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
$timeout = 5;
$cookie = tempnam ("/tmp", "CURLCOOKIE");
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false ); 
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl, CURLOPT_URL, $adres);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie );
$str = curl_exec($curl);  
 curl_close($curl);
 /code for extracting data from DOM
}

while ($limit != $sklep['limit']); 

}
?>

そして、その do {} のすべてのループが解析サーバーへの新しい接続と見なされ、〜 5 分後に 1000 人がオンラインになっていることが示されるという問題があります。1 つの長い接続を模倣するようにコードを変更するにはどうすればよいですか? PS。私の悪い英語でごめんなさい:)

4

1 に答える 1

0

そのためにhttp://php.net/manual/en/function.curl-multi-exec.phpを使用できます。いくつかの実用的な例があります

于 2013-02-25T10:15:31.183 に答える