【问题标题】:Cannot write to file on Google App Engine Dev server with PHP?无法使用 PHP 在 Google App Engine 开发服务器上写入文件?
【发布时间】:2023-04-10 15:41:01
【问题描述】:

就在几个小时前,我才真正开始了这项工作。不知道我做了什么把它搞砸了,如果有的话。我正在尝试使用 file_put_contents() 到我的临时目录中的 test.txt 文件来测试一些东西。我不能使用 print_r() 或 echo,因为有时它是我正在测试的 ajax 调用。我不断收到的错误是:

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

我不在生产中。这是本地的,根据文档,这应该可以工作:

在开发网络服务器中存储数据

Google App Engine for PHP 支持通过 PHP 的流 API 读取和写入 Google Cloud Storage。开发人员可以通过将对象指定为支持 PHP 流实现的任何 PHP 函数(例如 fopen()、fwrite() 或 get_file_contents() 的 URI)来读取和写入 Google 云存储中的对象。

在开发服务器中,当指定 Google Cloud Storage URI 时,我们通过读取和写入用户本地文件系统上的临时文件来模拟此功能。这些文件在请求之间保留,允许您在将代码部署到 App Engine 之前在本地开发环境中测试功能。

在像 fopen() 这样的 PHP 开发服务器流式调用中,'gs://' url 上的 file_get_contents() 通过读取和写入本地文件系统来模拟。

我很沮丧,所以非常感谢任何帮助。会投票。

【问题讨论】:

  • FWIW "temp/test.txt" 不是云存储路径。在 1.9.18 中,我们添加了对内存临时文件系统的支持,因此您可以执行类似 file_put_contents(sys_get_temp_dir() . '/test.txt', 'blah') 之类的操作

标签: php google-app-engine development-environment file-writing


【解决方案1】:

从 SDK 1.9.18 开始,dev_appserver 默认禁用本地文件写入,以更好地模拟生产环境。您可以通过将“google_app_engine.disable_readonly_filesystem=1”添加到您的 php.ini 文件来启用文件写入。

【讨论】:

    【解决方案2】:

    虽然您是对的,但开发服务器应该能够模拟 Google Cloud Storage,但目前存在一个问题(已报告 here,请随意加注星标)。

    如果您使用的是 SDK 版本 1.9.18,只需恢复到 1.9.17,它应该可以工作(至少对我有用)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    相关资源
    最近更新 更多