alex
alex

Reputation: 490133

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

Upvotes: 3

Views: 456

Answers (1)

Matthew
Matthew

Reputation: 48284

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.

Upvotes: 5

Related Questions