我有相当广泛的PHP脚本,我必须在我的数据库上运行,以及从文件结构收集img大小并将该信息写入XML文件。我已经尝试直接从Web浏览器运行,但成功最少,因为Gateway在大约3分钟后超时。我尝试从ssh shell运行也没有成功。这是大部分脚本
//Get all galleries from client
$query = mysql_query("SELECT *
FROM gallery
WHERE clientRef BETWEEN 420
AND 430
ORDER BY clientRef
");
while ($row = mysql_fetch_array($query)) {
//set gallery id
$galleryID = $row['id'];
$clientRef = $row['clientRef'];
//Check image sizes and set horizontal vs vertical
$fImageSizeName = mysql_fetch_array($qAlbumImages);
$imageSizeName = $fImageSizeName['OrgImageName'];
$galleryPath = $_SERVER['DOCUMENT_ROOT'] . "/data/gallery/" . $galleryID . "/images/";
if(is_dir($galleryPath)) {
list($width, $height) = getimagesize($_SERVER['DOCUMENT_ROOT'] . "/data/gallery/" . $galleryID . "/images/album/" . $imageSizeName);
header("Content-Type: text/plain");
//Create the xml document
$xmlDoc = new DOMDocument();
//Create the root Element
$root = $xmlDoc->appendChild(
$xmlDoc->createElement("PageflipDataSet"));
//Create settings element
$settings = $root->appendChild(
$xmlDoc->createElement("Settings"));
//Create PageOrder Node
$PageOrder = $root->appendChild(
$xmlDoc->createElement("PageOrder"));
$qAlbumImages = mysql_query(" SELECT *
FROM galleryimage
WHERE galleryId='{$galleryID}'
AND clientRef= '{$clientRef}'
ORDER BY sort
");
while ($fAlbumImages = mysql_fetch_array($qAlbumImages)) {
$path = "../../../../data/gallery/" . $galleryID . "/images/album/" . $fAlbumImages['OrgImageName'];
//Create the PageData Node
$PageData = $PageOrder->appendChild(
$xmlDoc->createElement("PageData"));
//PageFile attribute
$PageData->appendChild(
$xmlDoc->createAttribute("PageFile"))->appendChild(
$xmlDoc->createTextNode($path));
}//close while
//Format output so it looks pretty
$xmlDoc->formatOutput = true;
//Save and create path to gallery ID
$galleryPath = $_SERVER['DOCUMENT_ROOT'] . "/data/gallery/" . $galleryID;
//Set path
if(is_dir($galleryPath)) {
$xmlPath = $_SERVER['DOCUMENT_ROOT'] . '/data/gallery/' . $galleryID . '/xml/pageflipdata.xml';
$xmlDoc->save($xmlPath);
}
}//close while
关于我应该怎样做的任何建议。大约有2000个clientRef,每个clientRef有5-10张专辑,可以包含15-30张图片。
答案 0 :(得分:2)
如果超时是主要问题,您可以在较小的块中执行此操作,然后手动组合xml。
如果这需要定期运行,您可以使用类似的过程,但使用ajax或其他东西在不同的请求中运行每个“较小的块”等待所有小块脚本的确认以运行xml组合脚本。
当然,简单地增加PHP的max_execution_time会更容易。如果您无法访问此功能,则可以通过监视执行时间然后调用set-time-limit再次重置计时器来调整某些工作顺序。我从来没有试过这个,所以只是一个想法。