Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP shutdown: Can't write files?

I'm using a Log class to store messages during execution, and then it is supposed to write these messages to a file on shutdown (with register_shutdown_function).

But for some reason, I'm always getting "file_put_contents failed to open stream: No such file or directory". It shouldn't be a problem that the file doesn't exist, file_put_contents should create the file. In fact, everything works just fine if I do the write during execution (ie: before the shutdown function is called).

Is this a php bug?

like image 968
HappyDeveloper Avatar asked Nov 22 '10 05:11

HappyDeveloper


1 Answers

Make sure you use an absolute path. Relative paths aren't guaranteed to work in the shutdown function.

like image 89
Matthew Avatar answered Oct 31 '22 22:10

Matthew