chobo
chobo

Reputation: 32291

How to stop or pause php execution?

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.

Upvotes: 19

Views: 51711

Answers (5)

user1483887
user1483887

Reputation: 11

I like to keep it in the family, one file....

 if (@$_GET['thispic']){
    dizzy($_GET['thispic']);
    exit;
    }


    function dizzy($thispic){
    $PSize = filesize($thispic);
    $mysqlPicture =  fread(fopen($thispic, "r"), $PSize) ; 
    ///add file type checking here
    Header( "Content-type: image/jpg") ;
    echo $mysqlPicture;
    }


    $Picture = "images/brand.jpg";
    echo "<img src = \"test.php?thispic=$Picture \" height = \"300\">"; 

I use similar script for thumbnails from a database. to avoid the base64 decoding thus saving load time.

contact: [email protected]

Upvotes: 0

Maxime Pacary
Maxime Pacary

Reputation: 23041

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.

Upvotes: 7

meouw
meouw

Reputation: 42140

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

You'd really enjoy a proper debugger though

Upvotes: 19

Sameer Parwani
Sameer Parwani

Reputation: 309

Here:

print_r($whatever);    
exit();

Upvotes: 5

linus72982
linus72982

Reputation: 1393

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.

Upvotes: 2

Related Questions