php正在运行将要停止的进程
我在一个电子商务网站上工作 我想从CSV或TXT文件中读取数据。第一次从1到1000读取数据时,进程意外停止。所以第二次读取过程应该从1001开始 任何人请帮帮我 选项1 将元素逐个插入到表中,如下所示:php正在运行将要停止的进程,php,Php,我在一个电子商务网站上工作 我想从CSV或TXT文件中读取数据。第一次从1到1000读取数据时,进程意外停止。所以第二次读取过程应该从1001开始 任何人请帮帮我 选项1 将元素逐个插入到表中,如下所示: // take all data $prods = json_decode(file_get_contents('products.php')); while (!empty($prods)) { // remove first element from array. Origin
// take all data
$prods = json_decode(file_get_contents('products.php'));
while (!empty($prods)) {
// remove first element from array. Origin array is changed
$product = array_shift($prods);
// do your insert logic
$this->insert($product);
// for some reasons you don't insert all products
if ($this->break) {
break;
}
}
// write to file what is left, if any
file_put_contents('products.php', json_encode($prods));
选择2
在未到达元素时,按ID和空循环对产品进行排序:
foreach ($products as $product) {
if ($product->id < $lastId) {
continue;
}
$this->insert($product);
}
事实上,这是一个常见的概念,而且我不知道我将给出哪些代码,因为有太多的编码行。我只是保存了行id或行id,在第二次阅读时,我只是跳过了行,直到特定的行id出现。感谢您的回复,但这对我来说不起作用。原因是Option1==>产品总数超过11 lac,因此如果我存储,则时间将太长。选项2==>产品ID是随机的。