google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

Warning: touch(): Google\Cloud\Storage\StreamWrapper::stream_metadata is not implemented!

Open icedevelopment opened this issue 3 years ago • 2 comments

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

  1. Install the latest WordPress and GCS plugin.
  2. 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!

icedevelopment avatar Feb 14 '22 14:02 icedevelopment

Just wanted to add that the problem is the same with chmod(), chown() and chgrp() since they all call streamWrapper::stream_metadata().

icedevelopment avatar Feb 15 '22 14:02 icedevelopment

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.

saranshdhingra avatar Feb 25 '22 12:02 saranshdhingra

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.

vishwarajanand avatar Mar 13 '24 12:03 vishwarajanand