これは、AJAXを通じて大量のデータを処理する場合にのみ有効です。それ以外の場合は、キャンセルした場合は結果を表示しないようにJS内で処理してください。
大量のデータを処理している場合、スクリプトを実行するn番目のステップごとに割り込み条件を追加し、別のスクリプトを使用してその条件を満たすことができます。たとえば、ファイルを使用して割り込みデータまたはMySQL MEMORYテーブルを格納することができます。
例。
1、process.php(データのAJAXスクリプト処理負荷)
// clean up previous potential interrupt flag
$fileHandler = fopen('interrupt_condition.txt', 'w+');
fwrite($fileHandler, '0');
fclose($fileHandler);
function interrupt_check() {
$interruptfile = file('interrupt_condition.txt');
if (trim($interruptfile[0]) == "1") { // read first line, trim it and parse value - if value == 1 interrupt script
echo json_encode("interrupted" => 1);
die();
}
}
$i = 0;
foreach ($huge_load_of_data as $object) {
$i++;
if ($i % 10 == 0) { // check for interrupt condition every 10th record
interrupt_check();
}
// your processing code
}
interrupt_check(); // check for last time (if something changed while processing the last 10 entries)
2、interrupt_process.php(AJAXスクリプトファイルにイベントをキャンセル伝播する)
$fileHandler = fopen('interrupt_condition.txt', 'w+');
fwrite($fileHandler, '1');
fclose($fileHandler);
これは間違いなく影響を与えますスクリプトのパフォーマンスは向上しますが、実行を終了させるバックドアになります。これは非常に単純な例です - 非永続キャッシュサーバまたは任意の非 - あなたはそれが同時により多くのユーザーのために動作させるために、それをより複雑にする必要がある、など
また、MEMCACHEをMySQLのメモリテーブルを使用することができますあなたが見つけることができる - 永続的なストレージ。