0
我正在开发一个解析器,每次解析器都会将图像从URL复制到远程服务器,并将详细信息保存在MySql数据库中。我正在做的是这样的:循环运行正好20次,但MySql数据库仅插入数据16次
function scrap_photo($frompage, $permalink, $url, $message, $createdtime, $type, $imgid) {
global $last_cron_timestamp;
global $cxn;
if ($createdtime > $last_cron_timestamp && $type == "photo") {
$current_time_stamp = round(microtime(true) * 1000);
$imgpath = "photo/".$current_time_stamp.".jpg";
echo $imgpath;
$fp = fopen($imgpath, "w");
$handle = curl_init();
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_TIMEOUT, 300);
curl_setopt($handle, CURLOPT_FILE, $fp);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_exec($handle);
curl_close($handle);
fclose($fp);
$query = "INSERT INTO images (permalink, url, message, createdtime, imgid, frompage, type, photo_name, photo_path) VALUES ('$permalink', '$url', '$message', '$createdtime', '$imgid', '$frompage', '$type', '$current_time_stamp', '$imgpath')";
mysqli_query($cxn, $query);
}
}
这个功能'scrap photo'正被用来保存图像到目录并在数据库中写入详细信息。
我面对的问题是,循环运行20次,该函数被调用20次,甚至在文件夹中的图像计数是20,但在MySql数据库中,只有16个查询被插入。
我不明白如何或为什么,帮助!
我在这里看不到循环。 –
你认为独特的钥匙? – barudo
是的,循环在那里,每次都调用这个函数。 –