如何停止或暂停 php 执行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5505846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:39:18  来源:igfitidea点击:

How to stop or pause php execution?

php

提问by chobo

I want to do some basic debugging with print_r.

我想用print_r 做一些基本的调试。

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

当 PHP 到达该行时,我希望它停止或结束人们通常所做的任何事情,以便我可以看到输出。

采纳答案by meouw

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

You'd really enjoy a proper debuggerthough

你会很享受适当的调试器,虽然

回答by Frosty Z

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

要在 PHP 中停止执行,您可以使用dieexit

For advanced debugging, use tools such as XDebug.

对于高级调试,请使用XDebug等工具。

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

或睡眠:sleep(30);延迟 30 秒。

回答by Sameer Parwani

Here:

这里:

print_r($whatever);    
exit();

回答by linus72982

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.

这将结束代码的执行并回显您放在引号之间的消息 - 这可以是您需要调试的字符串或整数,我在调试时经常使用它。半分割效果很好,将 var_dumps 放在代码的一半,最后放一个骰子,找出哪一半出了问题,将其分成两半,等等,直到你达到可以从逻辑上猜测错误所在的地步,开始调试语法/等。

回答by user1483887

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.

我对数据库中的缩略图使用类似的脚本。避免 base64 解码从而节省加载时间。

contact: [email protected]

联系方式:[email protected]