|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70357 OPcache status is unavailable in shutdown
Submitted: 2015-08-25 12:20 UTC Modified: 2021-07-14 09:08 UTC
From: viktor at szepe dot net Assigned:
Status: Open Package: opcache
PHP Version: 7.0.0RC1 OS: Debian 8.1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-08-25 12:20 UTC] viktor at szepe dot net
opcache_get_status() returns false in shutdown but not before it.

PHP 7.0.0-dev (cli) (built: Aug 17 2015 19:10:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

Test script:
function o1_opcache() {
    var_export( opcache_get_status() ); // false
register_shutdown_function( 'o1_opcache' );

Expected result:
OPcache status

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-25 12:21 UTC] viktor at szepe dot net
 [2015-08-26 06:13 UTC]
I can not reproduce this.... 

$ sapi/cli/php /tmp/1.php
array (
  'opcache_enabled' => true,
  'cache_full' => false,
  'restart_pending' => false,
  'restart_in_progress' => false,
  'memory_usage' =>

 [2015-08-26 06:48 UTC] viktor at szepe dot net
I also get right output on cli:
php -d opcache.enable_cli=1 1.php

Could it be that my php.ini has wrong settings?

Opcode Caching 	Up and Running
Optimization 	Enabled
Startup 	OK
Shared memory model 	mmap
Cache hits 	107450
Cache misses 	798
Used memory 	36095392
Free memory 	30976152
Wasted memory 	37320
Interned Strings Used memory 	4194272
Interned Strings Free memory 	32
Cached scripts 	784
Cached keys 	1350
Max keys 	3907
OOM restarts 	0
Hash keys restarts 	0
Manual restarts 	0 

opcache.blacklist_filename	no value	no value
opcache.consistency_checks	0	0
opcache.dups_fix	Off	Off
opcache.enable	On	On
opcache.enable_cli	Off	Off
opcache.enable_file_override	Off	Off
opcache.error_log	no value	no value
opcache.fast_shutdown	1	1
opcache.file_update_protection	2	2
opcache.force_restart_timeout	180	180
opcache.inherited_hack	On	On
opcache.interned_strings_buffer	4	4
opcache.log_verbosity_level	1	1
opcache.max_accelerated_files	2000	2000
opcache.max_file_size	0	0
opcache.max_wasted_percentage	5	5
opcache.memory_consumption	64	64
opcache.optimization_level	0xFFFFFFFF	0xFFFFFFFF
opcache.preferred_memory_model	no value	no value
opcache.protect_memory	0	0
opcache.restrict_api	/home/wp/website/	/home/wp/website/
opcache.revalidate_freq	0	0
opcache.revalidate_path	Off	Off
opcache.save_comments	1	1
opcache.use_cwd	On	On
opcache.validate_timestamps	On	On
 [2015-08-26 06:58 UTC] viktor at szepe dot net
It is very strange: after disabling opcache.restrict_api it is OK.
But opcache.restrict_api was "/home/wp/website/" and the only script is:

  'scripts' => 
  array (
    '/home/wp/website/html/opcache-status-in-shutdown.php' => 
    array (
      'full_path' => '/home/wp/website/html/opcache-status-in-shutdown.php',
      'hits' => 0,
      'memory_consumption' => 1288,
      'last_used' => 'Wed Aug 26 08:54:46 2015',
      'last_used_timestamp' => 1440572086,
      'timestamp' => 0,

How should I use opcache.restrict_api to get OPcache status?
 [2015-08-26 06:59 UTC] viktor at szepe dot net
Docs says:

If opcache.restrict_api is in use and the current path is in violation of the rule, an E_WARNING will be raised; no status information will be returned. 

Does '/home/wp/website/html/opcache-status-in-shutdown.php' violate "/home/wp/website/" ?
 [2015-08-26 07:02 UTC] viktor at szepe dot net
Maybe the current path changes in shutdown??
 [2015-08-26 07:05 UTC] viktor at szepe dot net
Yes. getcwd() returns "/" in shutdown.
Even setting opcache.restrict_api to "/" does not help.

Please advise.
 [2015-09-04 16:28 UTC]
From register_shutdown_function():

  Working directory of the script can change inside the shutdown function under some web servers, e.g. Apache.

Not sure what we can do about that as this sort of behavior have always been like it around other places of PHP
 [2015-09-04 18:35 UTC] viktor at szepe dot net
I think opcache.restrict_api is not interested in cwd but the path of the queried PHP script.

Before 7.0 I was able to get OPcache status in shutdown.
 [2021-07-13 14:59 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-07-13 14:59 UTC]
I cannot reproduce this with PHP-7.4 (apache2handler on Windows).
So either the issue has been resolved in the meantime, or there is
some relevant difference in our setups.  Do you still experience
this issue with any of the actively supported PHP versions[1]?
Which SAPI are you using?

[1] <>
 [2021-07-13 17:05 UTC] viktor at szepe dot net
Thank you!
PHP 7.4 FPM works the same way. In shutdown function opcache.restrict_api makes opcache_get_status return false.

I should live with it.
I leave all this up to you!
 [2021-07-14 09:08 UTC]
-Status: Feedback +Status: Open -Type: Bug +Type: Documentation Problem -Assigned To: cmb +Assigned To:
 [2021-07-14 09:08 UTC]
Ah, FPM.  I can't help with that, but want to point out that this
issue is related to SG(request_info).path_translated[1] which is
apparently changed during shutdown.

Given that it behaves this way for many years now, I think it's
best to document the issue.

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 02:01:28 2024 UTC