我正在开发一个解析器,每次解析器将图像从URL复制到远程服务器,并将详细信息保存在MySql数据库中。我在做什么是这样的:
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'用于将图像保存到目录并在DB中写入详细信息。
我面临的问题是,循环运行20次,此函数被调用20次,甚至文件夹中的图像数为20,但在MySql数据库中,只插入了16个查询。 / p>
我无法弄清楚如何或为什么,帮助!
答案 0 :(得分:0)
if ($createdtime > $last_cron_timestamp && $type == "photo") {
通过这20张照片,null
,而数据库不允许它们为null
。