According to the documentation to exit:
If status is an integer, that value will be used as the exit status and not printed.
This made me very confused. What is the difference between a exit(); and a exit(1);? What are the use cases? How should I choose? On what occasions? How php manages this state?
The difference between
exit();andexit(1);is, that the former sets the exit status of the process executing your PHP script to0and the latter sets it to1.An exit status of
0usually means that the process finished sucessfully. No error occurred.An exit status of
1to254usually 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.