How do I pause execution in php, save state and continue from same point later on?

405 Views Asked by At

I have a php program which does some processing. I would like to stop the program during execution and save the current execution state and continue from some point later on. What is the best way to achieve this?

Edit

For example my scenario is like this:

<?php
.........
foreach($items as $item)
{
    .........

    // Stop execution from here during 4th looping and save this execution state
    // and continue after some time from here it self as the 4th loop execution

    .........
}
.........
?>

I know I can achieve my requirement by sleeping the process of execution. But during sleep process' working set still requires physical memory and/or pagefile to support that process. In other words, the PHP interpreter process needs to keep running. I would like to avoid this. That is why I am looking for an alternate method like save entire execution state and continue after some time by loading saved execution state from memory. This may be compared to hibernation of a process for an amount of time.

1

There are 1 best solutions below

0
On

I am not sure you framed your objective very well. But, that maybe ignorance on my part. However, it seems to me that threads maybe the solution to your problem. Apparently threads are now possible in php. I would offer you more information, but I have no personal experience with the API I am about to recommend. I only say this out of honesty, because I am not 100% that this will solve your problem. But, if you added threads you would be able to perform your operations concurrently and shouldn't have to worry about serializing your variables or sleeping your program. Hope this helps.

ptthreads project