Asked 7 years ago
31 Mar 2017
Views 2201

posted

how to stop PHP script run in halfway of execution ?


include("abc.php");

...
..
..

//code complete

i set the cron to run it daily . above PHP script process the some api data which is million so it take about 3 to 4 hour to run full code.

now suppose i have web page . where i click the stop process it should stop the currently running background PHP script.

so is there any way where i can stop the background running script in PHP ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

you can set some session variable or something on file storage or data storage so it will become off when you click on the stop button of your web page.

session_start();
$_SESSION['die']=1;

and try to access the stored variable and check it whether it on/off , if it on than continue to run other wise stop the running code


include("abc.php");
if($_SESSION['die'])
die("Stopped procedure by User");
...
..
..

//code complete
Post Answer