- Class Test {
- Public Function __construct () {
- $this->_log (' Start ');
- }
- Public Function __destruct () {
- $this->_log (' Finish ');
- }
- Public Function _log ($STR) {
- error_log ($str. "\ n", 3, './log.log ');
- }
- }
- $test = new test;
- ?>
Copy CodeFound in Log.log only start, no finish. After emptying the contents of the log, modify the program: unset ($test); Sure enough, with start, and finish. It seems that it is really unset to execute __destruct. But the thing is not over, I modified the program, changed the __destruct function, while deleting the Code of unset:
- Public Function __destruct () {
- Echo ' Finish ';
- $this->_log (' Finish ');
- }
- ?>
Copy CodeThe screen actually prints out ' finish ', which proves that the destructor was actually executed. Baffled after the solution, began to find information on the Internet, see a friend of the destructor used in the error_log and executed, and I use the difference is that he did not specify the Error_log file, but to the default log file, so I simulated a bit, and modified my program:
- Public Function _log ($STR) {
- Error_log ($str. "\ n");
- Error_log ($str. "\ n", 3, './log.log ');
- }
- ?>
Copy CodeI found Log.log still after start, no finish. and E:\AppServ\Apache2.2\logs\error.log (the default log log file for my Apache configuration) really has start and finish. Strange question, can't think of, so went to the group inside asked, the group of friends either let me check the syntax error, or check the file permissions, I am sure that these two do not have any problems. I said "Windows system, there is no permission problem, certainly not this caused" a group of friends said: "WinDOS system, do not explain! "I said," This certainly doesn't matter with the system, I suspect it's Apache's problem. "So I restored the _log, to the Linux+nginx of the virtual machine ran a bit."
- Public Function _log ($STR) {
- Error_log ($str. "\ n", 3, './log.log ');
- }
- ?>
Copy CodeStart and finish were successfully written in Log.log. This makes me more skeptical of my judgment: Apache leads to So it took one hours to install Apache on the server and run the file, or the same result, finish did not write successfully. At this time a colleague told me that you write the absolute path to try, so I modified a _log
- Public Function _log ($STR) {
- Error_log ($str. "\ n", 3, '/var/www/apache/log.log ');
- }
- ?>
Copy CodeLook again, successfully write "Finish", excited Ah, finally found the problem, I modified the program
- Public Function __construct () {
- Echo GETCWD (). '
';
- }
- Public Function __destruct () {
- Echo GETCWD (). '
';
- }
- ?>
Copy CodeView running results:/var/www/apache/ Then to the Nginx server to run, get the result:/var/www/apache/var/www/apache The original Apache destructor will change the current program's directory, so the relative directory, you can not find the corresponding file, write of course also failed. It's not easy to learn a language, it's good to practise more. |