doutao4938 2012-07-04 08:08
浏览 21
已采纳

运行广泛的PHP脚本 - 编写XML

I have quite an extensive PHP script that I have to run on my database as well as gather img sizes from the file structure and write that information to an XML file. I have tried running directly from the web browser with minimum success as the Gateway times out after about 3 minutes. I have tries running from an ssh shell as well with no success. here is most of the script

    //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

Any suggestions on how I should go about doing this. There are about 2000 clientRef and each of the clientRef have 5-10 albums which can contain 15-30 images.

  • 写回答

1条回答 默认 最新

  • duanjianxiu9400 2012-07-04 09:10
    关注

    If timeout is the primary issue, you could just do it in smaller chunks and combine the xml later manually.

    If this needs to run regularly, you can use a similar process but run each 'smaller chunk' in a different request using ajax or something to wait for confirmation from all the small chunk scripts to run an xml combination script.

    Of course simply increasing the max_execution_time of PHP would be easier. If you don't have access to this, you might be able to tweak something into working order by monitoring execution time and then calling set-time-limit to reset the timer again. I've never tried this, though, so just an idea.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛