Cannot write to file on Google App Engine Dev server with PHP?

旧巷老猫 提交于 2019-12-24 12:16:39

问题


I had this working literally just a few hours ago. Not sure what I did to mess it up, if anything. I am trying to use file_put_contents() to a test.txt file in my temp directory to test some stuff. I can't use print_r() or echo, because sometimes it is an ajax call I am testing. The errors I keep getting are:

Warning: file_put_contents(temp/test.txt): The local filesystem is readonly, open failed in sub-dirs.../request.php on line 62

Warning: file_put_contents(temp/test.txt): failed to open stream: No such file or directory in sub-dirs.../request.php on line 62

I am not on production. This is locally, and according to the docs, this should work:

Storing data in the development web server

Google App Engine for PHP supports reading and writing to Google Cloud Storage via PHP's streams API. A developer can read to and write from an object in Google cloud storage by specifying it as a URI to any PHP function that supports PHPs Streams implementation such as fopen(), fwrite() or get_file_contents().

In the Development Server, when a Google Cloud Storage URI is specified we emulate this functionality by reading and writing to temporary files on the user's local filesystem. These files are preserved between requests, allowing you to test the functionality on your local development environment before deploying your code to App Engine.

In the PHP development server streaming calls like fopen(), file_get_contents() on 'gs://' urls are mocked by reading and writing to the local filesystem.

I'm pretty frustrated, so any help is greatly appreciate. Will upvote.


回答1:


Staring SDK 1.9.18, dev_appserver disables local file writing by default to better simulate the production environment. You can enable file writing by adding "google_app_engine.disable_readonly_filesystem=1" to your php.ini file.




回答2:


While you're right, the development server should be able to simulate Google Cloud Storage, there is currently an issue (reported here, feel free to star it) about it.

If you're using the SDK version 1.9.18, just revert back to 1.9.17 and it should work (did for me at least)



来源:https://stackoverflow.com/questions/28774537/cannot-write-to-file-on-google-app-engine-dev-server-with-php

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