PHP shutdown: Can't write files?

旧街凉风 提交于 2019-12-10 14:19:55

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4242534/php-shutdown-cant-write-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!