2

根据文档退出:

如果 status 是一个整数,则该值将用作退出状态而不打印。

这让我很困惑。aexit();和 a 和有什么不一样exit(1);?有哪些用例?我应该如何选择?在什么场合?php如何管理这种状态?

4

4 回答 4

3

操作系统/外壳程序/调用您的 PHP 脚本的进程可以读取一个数字返回码。见:http ://en.wikipedia.org/wiki/Exit_status

于 2012-07-19T15:37:18.097 回答
1

我相信只有在从命令行执行脚本或另一个程序正在执行它时才有用,通过网络服务器它是没有意义的。

于 2012-07-19T15:37:04.747 回答
1

exit();和之间的区别在于exit(1);,前者将执行 PHP 脚本的进程的退出状态0设置为,而后者将其设置为1.

退出状态0通常意味着进程成功完成。没有发生错误。

An exit status of 1 to 254 usually is used to signal that the process was aborted because some kind of error occurred. What error a specific exit status means is up to your PHP script.

Parent processes can use the exit statuses returned by child processes to decide how to continue, e.g. whether they should exit too, or retry, or execute another child process, or whatever.

于 2012-07-19T22:09:37.950 回答
0

它就像 C++ 中的返回代码一样,通常程序在一切成功完成时返回 0,在发生某些错误时返回负数,正数取决于可以使用该代码的位置。

但总的来说,正如之前的答案中已经说过的那样,如果脚本不会从另一个脚本或程序中调用,那么返回什么没有多大意义

于 2012-07-19T15:40:06.127 回答