google-cloud-php
google-cloud-php copied to clipboard
Warning: touch(): Google\Cloud\Storage\StreamWrapper::stream_metadata is not implemented!
Hi,
I'm getting the following PHP warning: Warning: touch(): Google\Cloud\Storage\StreamWrapper::stream_metadata is not implemented!
when trying to install a 3rd party WordPress plugin that calls the touch()
PHP function.
Internally PHP calls streamWrapper::stream_metadata()
as mentionned in its documentation which is indeed not implemented in Google\Cloud\Storage\StreamWrapper in the GCS WordPress plugin.
The issue looks similar to https://github.com/googleapis/google-cloud-php/issues/4744 (fixed in https://github.com/googleapis/google-cloud-php/pull/5067).
Environment details
- OS: Google App Engine Standard
- PHP version: 7.2
- Package name and version: google/cloud-storage v1.22.0 (from https://wordpress.org/plugins/gcs/ 0.1.6) on WordPress 5.9.
Steps to reproduce
- Install the latest WordPress and GCS plugin.
- Run PHP code calling touch() after Google\Cloud\Storage\StreamWrapper::register has been called, for example at the beginning of your theme functions.php.
Code example
<?php
// wp-content/themes/twentytwentytwo/functions.php
touch('gs://my-storage/1/file.txt');
// ...
@saranshdhingra @bshaffer could any of you have a look at this please?
Thanks!
Just wanted to add that the problem is the same with chmod(), chown() and chgrp() since they all call streamWrapper::stream_metadata().
Hi @icedevelopment Just to update you.
The fix for removing the warning is simple as you already have discovered.
However, the methods touch
, file_put_contents
(with an empty string) and fwrite
with empty data aren't yet working.
So, for your particular use case, just fixing the warning may not work.
I will however keep you updated on this.
I attempted a change and it seems to fix the issue of warnings, but it indeed does not make any file.
So, I added the code to create a file in stream_metadata
.
However, I am unable to get file_put_contents and fwrite working for empty files. I think thats okay, since we have touch as a workaround.