我有这样的代码:PHP卷曲的问题 - 运行多次
<?php
foreach($items as $item) {
$site = $item['link'];
$id = $item['id'];
$newdata = $item['data_a'];
$newdata2 = $item['data_b'];
$ch = curl_init($site.'updateme.php?id='.$id.'&data1='.$newdata.'&data2='.$newdata2);
curl_exec ($ch);
// do some checking here
curl_close ($ch);
}
?>
样品输入:
$site = 'http://www.mysite.com/folder1/folder2/';
$id = 512522;
$newdata = 'Short string here';
$newdata = 'Another short string here with numbers';
这里updateme.php
if (!$id = intval(Tools::getValue('id')))
$this->_errors[] = Tools::displayError('Invalid ID!');
else
{
$history = new History();
$history->id = $id;
$history->changeState($newdata1, intval($id));
$history->id_employee = intval($employee->id_employee);
$carrier = new Carrier(intval($info->id_carrier), intval($info->id_lang));
$templateVars = array('{delivery}' => ($history->id_data_state == _READY_TO_SEND AND $info->shipping_number) ? str_replace('@', $info->shipping_number, $carrier->url) : '');
if (!$history->addWithemail(true, $templateVars))
$this->_errors[] = Tools::displayError('an error occurred while changing status or was unable to send e-mail to the employee');
}
该网站的主要过程将总是在变化,每个$ items中至少有20个数据,所以foreach循环将运行至少20次或更多根据数据的数量。
目标站点将使用传递的变量更新其数据库,它可能会在保存到数据库之前通过至少5个函数,因此它可能也需要一些时间。
我的问题是这种方法会有问题吗?脚本在通过卷发过程时是否会遇到超时错误?如果$ items的数据大约是50,或者现在有几百个呢?
或者是否有更好的方法来做到这一点?
更新: *增加了updateme.php主进程代码。附加信息:updateme.php也会根据传递的变量发送一封电子邮件。
- 现在所有其他网站都托管在同一台服务器上。
这几乎肯定是这样做的低效方式。所有的curl请求是否都是针对不同的服务器的,或者它们全都是针对同一台服务器的?如果是这样,你能编辑代码到'updateme.php'吗? – lonesomeday 2010-10-06 13:39:15
现在所有的curl请求都将在同一台服务器上。 – GoDesigner 2010-10-06 14:02:35