我有这样的脚本:
function getNewProductToEcommerce($merk, $shopID){
// assuming I have called a database connection
-----------------------------------------------
$conn = intialitationDB();
-----------------------------------------------
$sql = "select * from tablebarang where merk = '".$merk."'";
$result = mysqli_query($conn, $sql);
$addNewProducts = array();
foreach($result as $products){
$tempSKU = searchEcommerceProducts($products['sku'], $shopID);
if($tempSKU === false){
$newProducts['sku'] = $products['sku'];
$newProducts['catID'] = getCatIdEcommerece($merk, $products['sku']);
$images = getPhotosSomeWebsite($merk, $products['sku']);
for($i=1; $i <= 5; $i++){
if(isset($images[$i-1])) $img = 'https://somewebsite.com/file/'.$images[$i-1];
else $img = '';
$newProducts['images_'.$i] = $img;
}
$addNewProducts['sku'][] = $products['sku'];
$addNewProducts['item'][] = $newProducts;
}
// Markup
// In here i should respone to user one by one, but i cannot because
i just need respone just some variable
}
return $addNewProducts;
mysqli_close($conn);
}
function searchEcommerceProducts($sku, $shopID){
$q = str_replace(" ","%2B", $sku);
$url = "https://somewebsite.com/search/product?shop_id=$shopID&ob=11&rows=80&start=0&device=desktop&source=shop_product&q=$q";
$html = file_get_contents($url);
$html = json_decode($html, true);
if($html["header"]["total_data"] >= 1) return true;
else return false;
}
function getCatIdEcommerece($merk, $sku){
$merk = str_replace(" ","%2B",$merk);
$sku = str_replace(" ","%2B",$sku);
$search = $merk . "%2B" . $sku;
$url = "https://somesite.com/search/product/v3?scheme=https&device=desktop&catalog_rows=0&rows=1&source=search&ob=23&st=product&q=".$search."&sc=0&user_id=470833&rows=60&unique_id=35e66d287a5d4cefb1a674678be311f4";
$html = file_get_contents($url);
$html = json_decode($html, true);
if (isset($html['data']['products'][0]['url'])){
$url = $html['data']['products'][0]['url'];
$cat_id = after_last ("catid%3D", $url);
}else $cat_id = '';
return $cat_id;
}
function getPhotosSomeWebsite($merk, $sku){
$search = str_replace(' ','%20',$merk.' '.$sku);
// assuming I have called a function name theCURL
-----------------------------------------------
$getFoto = theCURL("https://somesite.com/search_items/?by=relevancy&keyword=$search&limit=1&match_id=16775174&newest=0&order=desc&page_type=shop&__classic__=1",'GET','');
-----------------------------------------------
$getFoto = json_decode($getFoto, true);
$items = $getFoto['items'];
if(!empty($items)){
$idProduct = $items[0]["itemid"];
$getFoto = theCURL("https://somesite.com/item/get?itemid=$idProduct&shopid=16775174&__classic__=1",'GET','');
$getFoto = json_decode($getFoto, true);
return $getFoto['item']['images'];
} else return null;
}
解释 :
首先:我需要从我的抓取网站获取 SKU、CategoryID、ImagesURL 的变量,我没有在我的商店中输入商品,所以我不需要检查双重产品项目/重复产品。
第二:我从其他类调用函数getNewProductToEcommerce()
,只在数组中返回变量 SKU、CategoryID、ImagesURL。我需要将产品项目保存到 xlsx。
问题 :
在循环中,我只想获得一些我没有在我的商店中输入商品的产品,但是循环 1000 个 sku 产品需要很长时间并返回请求超时(仅适用于 100 个 sku 产品检查)。
我一直在使用 echo 在循环 foreach 中复制脚本,它对于这 1000 个 sku 产品工作正常,但是当我传递函数时它不能并返回错误“标题已由标题发送”。
我的问题
如何在我的问题中获得许多产品的退货功能而不会出现错误“标头已由标头发送”或请求超时?
如果有人能在这个问题上帮助我,我非常感激,谢谢。