0

データベースで実行するだけでなく、ファイル構造から img サイズを収集し、その情報を XML ファイルに書き込む必要がある非常に広範な PHP スクリプトがあります。ゲートウェイが約 3 分後にタイムアウトするため、Web ブラウザーから直接実行しようとしましたが、最小限の成功しかありませんでした。ssh シェルからも実行を試みましたが、成功しませんでした。ここにほとんどのスクリプトがあります

    //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 個の画像を含めることができます。

4

1 に答える 1

2

タイムアウトが主な問題である場合は、小さなチャンクでそれを実行し、後で手動で xml を組み合わせることができます。

これを定期的に実行する必要がある場合は、同様のプロセスを使用できますが、ajax または何かを使用して異なる要求で各「小さなチャンク」を実行し、すべての小さなチャンク スクリプトからの確認を待って xml 組み合わせスクリプトを実行できます。

もちろん、単純に PHP の max_execution_time を増やす方が簡単です。これにアクセスできない場合は、実行時間を監視してからset-time-limitを呼び出してタイマーを再度リセットすることで、何かを正常に動作するように微調整できる場合があります。ただし、これは試したことがないので、単なるアイデアです。

于 2012-07-04T09:10:49.020 に答える