0

I am developing a script that takes between 2-5 minutes to run. I am developing functionality about 4 minutes into the script, so while I develop I have to run the application again and again to get to the part I'm developing which can be quite time consuming.

Is there a way to start the script from where I want to too (with all the internal data such as arrays and variable saved) and then just step through the part of the code I'm developing?

Please let me know if there is a good solution for this, I am using Eclipse running on my Wamp Server and I am sure someone has come up with a solution.

superdee72
  • 61
  • 8
  • Questions asking us to recommend or find a book, tool, software library, ***tutorial*** or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – Jay Blanchard May 04 '16 at 17:59
  • I am asking if there is a way to step-through a specific point in my application thats running (so about 4 minutes into the script at a specific line), so that each time I develop this feature I can start and stop 4 minutes in without restarting the whole script and waiting. – superdee72 May 04 '16 at 18:04
  • No, this is not possible. – Jay Blanchard May 04 '16 at 18:04
  • I have never seen an off-the-shelf PHP interpreter that lets you take a snapshot and replay from the point of that snapshot. The demand for such a product should be rather low as programmers shouldn't be taught to program in a monolithic manner anymore. – kainaw May 04 '16 at 18:05
  • Thank you for your answer, perhaps something is fundamentally structured wrong how I am writing my application – superdee72 May 04 '16 at 18:10

1 Answers1

1

Assuming that the variables generated in the first 4 minutes are expected to remain the same then you can try something like this:


First round

<?php
// 4 minutes of code later...

file_put_contents('4_minute_snapshot.json', json_encode(get_defined_vars()));

die();

// new functionality testing

Subsequent rounds

<?php
$json_unique_identifier = json_decode(file_get_contents('4_minute_snapshot.json'));

foreach($json_unique_identifier as $k=>$v)
{
    $$k = $v; // $$k is not a typo :-)
}
unset($v, $json_unique_identifier);

// new functionality testing

Note, if you have resources or other things that are not json encode-able such as classes then you should identify those and manually set them just before the // new functionality testing part.

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77