PHP contains a bug where for certain user-space stream wrappers the constructor is not called: https://bugs.php.net/bug.php?id=40459 .

It will probably take a while before this bug is fixed and a new PHP version is released. My suggestion is to add code to the Amazon S3 stream wrapper to invoke the constructor if it hasn't been called.

The reason I hit on this bug was that file_exists('s3://file') calls AmazonS3StreamWrapper::url_open(). Because the constructor isn't called, $this->cache is false, so these file_exists() calls always call S3, even when the file has been cached.

Comments

Jorrit’s picture

Status: Active » Needs review
StatusFileSize
new3.66 KB

Please see attached patch.

justafish’s picture

I've submitted a patch for this to PHP https://github.com/php/php-src/pull/93

Jorrit’s picture

I wouldn't bet on getting it committed quickly: http://markmail.org/message/zhj7h34x2xzk6an5

klakegg’s picture

Looks like a fix is in, but it doesn't help today. Could we have it work correct now, and have the perfect code later?
https://github.com/php/php-src/pull/153

Jorrit’s picture

By the way: my patch works regardless of the fix in PHP.

klakegg’s picture

Status: Needs review » Reviewed & tested by the community

This bug is a showstopper.

justafish’s picture

Status: Reviewed & tested by the community » Needs work

Patch needs rerolling

Jorrit’s picture

Status: Needs work » Needs review

Here you go.

justafish’s picture

Status: Needs review » Needs work

@Jorrit please attach a patch

Jorrit’s picture

Status: Needs work » Needs review
StatusFileSize
new3.63 KB

Weird, I was sure it was there.

justafish’s picture

Status: Needs review » Fixed

Thanks, committed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Jorrit’s picture

By the way: this patch is not necessary anymore from PHP 5.4.7 and up, see http://www.php.net/ChangeLog-5.php#5.4.7 .