m90 saisのように、phpを使用するだけではできません。
ロールバックできる構造のようなトランザクションを操作します。条件が満たされた場合は、ajax呼び出しを行います。出力に何かを送信し、応答を受信し、ユーザーの操作を要求します。新しい呼び出しを続行し、トランザクションまたはロールバックをコミットします。
編集:
jQueryを使用したajax呼び出しの簡単な例:
function runthescript(continue,rollback){
$.ajax({
type: "POST",
url: "yourphpscript.php",
data: {
"isContinueing": (continue===true),
"isRollback": (rollback===true)
},
success: function(msg){
if(msg === "calling for user interraction"){// replace this by Enum or something more performant this is just for illustration
var answer = confirm("Want to continue?");
if(answer){
runthescript(true, false);
} else {
runthescript(false, true);
}
} else if(msg === "completed"){// replace this by Enum or something more performant this is just for illustration
alert('completed');
} else if(msg === "rolled back"){// replace this by Enum or something more performant this is just for illustration
alert('rolled back');
}
}
});
}
runthescript();
PHPの例
<?php
function checkStates(){
if($rows>500){
echo "calling for user interraction"; // replace this by Enum or something more performant this is just for illustration
//exit(); //you can use exit if absolutely necessary, avoid if not needed.
}
if($finished_condition_is_met){
echo "completed";// replace this by Enum or something more performant this is just for illustration
//exit(); //you can use exit if absolutely necessary, avoid if not needed.
}
}
if($_POST['isContinueing'] === true){
//run some continuing php
checkStates();
} else if($_POST['isRollback'] !== true){
//run some rolling back code
echo "rolled back";// replace this by Enum or something more performant this is just for illustration
//exit(); //you can use exit if absolutely necessary, avoid if not needed.
} else {
//run some starting php
checkStates();
}