简体   繁体   中英

Is the exit status in PHP only useful when running from the command line?

I was just reading the docs for PHP's exit construct.

It says you can pass an integer (0-254) which will become the exit code...

exit(5);

Is this only useful when running from PHP under CLI? Can Apache use the error code for anything? Will PHP running normally always use exit code 0 ?

Thanks

While hardly an authoritative answer, I'm not aware of any purpose that it (passing an integer to exit ) serves outside the CLI environment. Web servers traditionally just report the HTTP status code, and there's not any reason for them to look elsewhere for status codes.

You could take a look at PHP's source in the sapi directory. For example, in php_cli.c, you'll see exit(exit_status); near the end of the file. I assume the generic cgi interface uses it too. I doubt any of the web server interfaces use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM