Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Files driver, the get function sometimes throws a warning that the file does not exist #782

Closed
carlittoer opened this issue Jan 27, 2021 · 15 comments · Fixed by #784

Comments

@carlittoer
Copy link

carlittoer commented Jan 27, 2021

Configuration

  • **PhpFastCache version: 8.0.4
  • **PhpFastCache API version: 3.0.0
  • **PHP version: 7.3.26
  • **Operating system: CentOS

Describe the bug
Very rarely the get() function throws the following warning :
Warning: file_get_contents(.../Files/ae/95/ae950e72f6d3c0329c84fe06797c6fb2.txt): failed to open stream: No such file or directory, .../vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php @ 294

Expected behavior

Maybe before calling file_get_contents we should check if the file exists?

@carlittoer carlittoer changed the title Warning: file_get_contents(.../Files/ae/95/ae950e72f6d3c0329c84fe06797c6fb2.txt): failed to open stream: No such file or directory, .../vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php @ 294 Using the Files driver, the get function sometimes throws a warning that the file does not exist Jan 27, 2021
@github-actions
Copy link

Hello curious contributor !
Since it seems to be your first contribution, make sure that you've been:

  • Reading and searching out our WIKI
  • Reading and agreed with our Code Of Conduct
  • Reading and understood our Coding Guideline
  • Reading our README
    If everything looks unclear to you, tell us what 😄
    The Phpfastcache Team

@Geolim4
Copy link
Member

Geolim4 commented Jan 27, 2021

Hello,

This does not appears in tests I made to test under heavy I/O activity.

Are you running concurrent scripts that works on the same directory ?

Maybe before calling file_get_contents we should check if the file exists?

I don't want to introduce a new "file" check if it's not absolutely necessary because this would introduce a new "read" activity before file opening which would introduce a massive performance issue in some circumstances.

Can you show me your implementation please ?

Thanks you

@Geolim4 Geolim4 self-assigned this Jan 27, 2021
@Geolim4 Geolim4 added the 8.0 label Jan 27, 2021
@carlittoer
Copy link
Author

carlittoer commented Jan 27, 2021 via email

@Geolim4
Copy link
Member

Geolim4 commented Jan 27, 2021

Try enabling "preventCacheSlams" option before trying anything else:
https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV4%CB%96%5D-Configuration-Options#global-options

@carlittoer
Copy link
Author

carlittoer commented Jan 28, 2021 via email

@javagotchi
Copy link

Me too!
Just upgraded to latest 8.0.4. Running the 7 for years now, but the error which sometimes occur does not disappear, when nightly clearing all cached stuff...

Uncaught TypeError: unlink() expects parameter 1 to be a valid path, bool given in /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php:109
Stack trace:
#0 /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php(109): unlink(false)
#1 /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Driver.php(150): Phpfastcache\Util\Directory::rrmdir('/var/www/vhosts...')
#2 /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php(278): Phpfastcache\Drivers\Files\Driver->driverClear()
#3 /var/www/vhosts/xxx/httpdocs/mod_Admin/classes/class.n4.admin.controller.php(1062): Phpfastcache\Drivers\Files\Driver->clear()

Does the preventCacheSlams help here too?
Don't know what it is exactly for...

Thanks

@Geolim4
Copy link
Member

Geolim4 commented Jan 29, 2021

Me too!
Just upgraded to latest 8.0.4. Running the 7 for years now, but the error which sometimes occur does not disappear, when nightly clearing all cached stuff...

Uncaught TypeError: unlink() expects parameter 1 to be a valid path, bool given in /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php:109
Stack trace:
#0 /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php(109): unlink(false)
#1 /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Driver.php(150): Phpfastcache\Util\Directory::rrmdir('/var/www/vhosts...')
#2 /var/www/vhosts/xxx/httpdocs/lib/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php(278): Phpfastcache\Drivers\Files\Driver->driverClear()
#3 /var/www/vhosts/xxx/httpdocs/mod_Admin/classes/class.n4.admin.controller.php(1062): Phpfastcache\Drivers\Files\Driver->clear()

Does the preventCacheSlams help here too?
Don't know what it is exactly for...

Thanks

I will try to fix this one too since this can be easily patched.

Geolim4 added a commit to Geolim4/phpfastcache that referenced this issue Jan 29, 2021
Geolim4 added a commit to Geolim4/phpfastcache that referenced this issue Jan 29, 2021
@Geolim4 Geolim4 linked a pull request Jan 29, 2021 that will close this issue
6 tasks
Geolim4 added a commit that referenced this issue Jan 30, 2021
@Geolim4
Copy link
Member

Geolim4 commented Jan 30, 2021

Your both related issue should now be resolved.

Use "dev-master" in composer if you can't wait the next release (around mid-February).

Cheers,
Georges

@carlittoer
Copy link
Author

Hi !

Any new release soon ? I would prefer to use a stable release instead of dev-master.

Thanks.

@Geolim4
Copy link
Member

Geolim4 commented Apr 2, 2021

Hello,

Saturday or Sunday at least.

Sorry for delay.

@Geolim4
Copy link
Member

Geolim4 commented Apr 5, 2021

@carlittoer
Copy link
Author

Thank you !

@carlittoer
Copy link
Author

carlittoer commented Jul 22, 2021

Hi,

Even with the latest release (8.0.6) the "failed to open stream" warning is still appearing sometimes when hitting the same cache.

Can we suppress this warning by prepending @ before file_get_contents ?

Warning: file_get_contents(...): failed to open stream: No such file or directory: No such file or directory IOHelperTrait.php @ 297

@carlittoer
Copy link
Author

Hi !

Can we expect a fix for this ? Any ideas other than suppressing the warning?

Thanks.

@Geolim4
Copy link
Member

Geolim4 commented Jul 30, 2021

In my guess I think you have an issue on your server or something because I have many tests running on pfc, especially tests on Files drivers that write/delete a LOT of cache files in a couple of seconds and this bugs does not appears at all:

https://travis-ci.com/github/PHPSocialNetwork/phpfastcache/jobs/526644470#L3855

And at this time I'm unable to reproduce this bug.

Also, using the @ is considered as a bad practice and should not be used any more inside any PHP code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants