Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop or pause php execution?

Tags:

php

I want to do some basic debugging with print_r.

When PHP hits that line I want it to stop or end whatever people usually do, so I can see the output.

like image 435
chobo Avatar asked Mar 31 '11 20:03

chobo


4 Answers

// if you want a one liner:
die(print_r($stuff, true ));

You'd really enjoy a proper debugger though

like image 141
meouw Avatar answered Sep 23 '22 03:09

meouw


For stopping execution in PHP, you have for example die and exit.

For advanced debugging, use tools such as XDebug.

Or sleep: sleep(30); for a 30 second delay.

like image 43
Frosty Z Avatar answered Sep 22 '22 03:09

Frosty Z


Here:

print_r($whatever);    
exit();
like image 37
Sameer Parwani Avatar answered Sep 21 '22 03:09

Sameer Parwani


die("Script Stopped");

This will end execution of code and echo the message you put between the quotations - this can be a string or an integer you need to debug, I use it often when debugging. Half-split works well, put var_dumps halfway through your code, put a die at the end, find which half is going wrong, split that in half, etc, until you get to a point that you can logically guess where the error is and start debugging the syntax/etc.

like image 44
linus72982 Avatar answered Sep 23 '22 03:09

linus72982