-1

XML ファイルを読み取ってデータベースに追加するスクリプトを作成しました。これには XML Reader を使用しています。問題は、XML に 500,000 個の製品が含まれていることです。これにより、ページがタイムアウトします。これを達成する方法はありますか?

以下の私のコード:

$z = new XMLReader;
$z->open('files/NAGardnersEBook.xml');

$doc = new DOMDocument;

# move to the first node
while ($z->read() && $z->name !== 'EBook');

# now that we're at the right depth, hop to the next <product/> until the end of the tree
while ($z->name === 'EBook')
{

    $node = simplexml_import_dom($doc->importNode($z->expand(), true));

    # Get the value of each node
    $title = mysql_real_escape_string($node->Title);
    $Subtitle = mysql_real_escape_string($node->SubTitle);
    $ShortDescription = mysql_real_escape_string($node->ShortDescription);
    $Publisher = mysql_real_escape_string($node->Publisher);
    $Imprint = mysql_real_escape_string($node->Imprint);

    # Get attributes
    $isbn = $z->getAttribute('EAN');

    $contributor = $node->Contributors;
    $author = $contributor[0]->Contributor;
    $author = mysql_real_escape_string($author);

    $BicSubjects = $node->BicSubjects;
    $Bic = $BicSubjects[0]->Bic;

    $bicCode = $Bic[0]['Code'];

    $formats = $node->Formats;
    $type  = $formats[0]->Format;
    $price = $type[0]['Price'];
    $ExclusiveRights = $type[0]['ExclusiveRights'];
    $NotForSale = $type[0]['NotForSale'];


    $arr[] = "UPDATE onix_d2c_data SET is_gardner='Yes', TitleText = '".$title."', Subtitle = '".$Subtitle."', PersonName='".$author."', ImprintName = '".$Imprint."', PublisherName = '".$Publisher."', Text = '".$ShortDescription."', BICMainSubject = '".$bicCode."', ExcludedTerritory='".$NotForSale."', RightsCountry='".$ExclusiveRights."', PriceAmount='".$price."', custom_category= 'Uncategorised', drm_type='adobe_drm' WHERE id='".$isbn."' ";

    # go to next <product />

    $z->next('EBook');
    $isbns[] = $isbn;
}


foreach($isbns as $isbn){

    $sql = "SELECT * FROM onix_d2c_data WHERE id='".$isbn."'";

    $query = mysql_query($sql);

    $count = mysql_num_rows($query);
    if($count >0){

    } else{
        $sql = "INSERT INTO onix_d2c_data (id) VALUES ('".$isbn."')";               
        $query = mysql_query($sql);
    }

}



foreach($arr as $sql){
    mysql_query($sql);
}

ありがとうございました、

ジュリアン

4

6 に答える 6

1

関数set_time_limitを使用して、許容されるスクリプトの実行時間を延長するかmax_execution_time、php.ini で設定することができます。

于 2013-08-07T08:51:58.273 に答える
0

他の人が提案したように max_execution 時間を変更したくない場合は、タスクをいくつかの小さなタスクに分割し、サーバーにcron-job をいくつかの間隔で実行させることもできます。

例: 毎分 10.000 製品

于 2013-08-07T08:58:45.520 に答える
0

set_time_limit(0);PHPファイルの上に追加しようとし ましたか?

編集 :

ini_set('memory_limit','16M');

そこで制限を指定します。

于 2013-08-07T08:51:47.257 に答える
0

これらの vaiables を設定する必要があります。それらを変更する権限があることを確認してください

set_time_limit(0);
ini_set('max_execution_time', '6000');
于 2013-08-07T08:52:48.333 に答える