嗨,我正在用这个脚本解析一个网站(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 人在线,如何更改代码以模仿一个长连接?PS。对不起,我的英语不好 :)