php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79751 "VirtualProtect() failed" entries in apache error.log
Submitted: 2020-06-28 08:29 UTC Modified: 2021-12-01 11:07 UTC
Votes:43
Avg. Score:3.8 ± 1.0
Reproduced:41 of 41 (100.0%)
Same Version:12 (29.3%)
Same OS:21 (51.2%)
From: buschmann at nidsa dot net Assigned:
Status: Open Package: opcache
PHP Version: 8.0.0alpha1 OS: Windows Server 2019 64bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
41 - 20 = ?
Subscribe to this entry?

 
 [2020-06-28 08:29 UTC] buschmann at nidsa dot net
Description:
------------
When trying to load the opcache with php-scripts from tools and our application in a script to preload the opcache: (here one example line:)

<?php
 $bresult=opcache_compile_file('N:\Apache\tcpdf\include\tcpdf_colors.php');

I get multiple entries in the apache error.log file as :
...
[Sun Jun 28 09:58:00.642291 2020] [mpm_winnt:notice] [pid 6572:tid 548] AH00354: Child: Starting 64 worker threads.
VirtualProtect() failed
VirtualProtect() failed
...

This was the first operation (explicitly and manually called from a browser) after a fresh start from Apache/php as a service.

It seems that 2 entries per compile request are generated (without timestamp).

There are no errors reported in php_err.log.

The scripts have been successfully loaded into opcache as reported by 
https://github.com/amnuts/opcache-gui - version 2.5.4

The same preload script has been used under 7.x.y until 7.4.7 for a long time without this issue.


Environment:
- Windows server 2019 64bit Standard in a VM under HyperV
- Apache 2.43 64bit from apachelounge
- php 8 alpha1 64bit thread safe from php.net QA download
- php loaded as a module with php_module


Test script:
---------------
<?php
 $bresult=opcache_compile_file('N:\Apache\tcpdf\include\tcpdf_colors.php');


Expected result:
----------------
No error log entry in error.log


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-29 08:49 UTC] nikic@php.net
Does the problem go away if you set opcache.protect_memory=0? This is an debugging setting, that should not be enabled for production opcache use.

Of course, it still shouldn't cause failures...
 [2020-06-29 15:42 UTC] buschmann at nidsa dot net
when I set opcache.protect_memory=0 (verified in php_info

opcache.protect_memory	Off	Off)

the problem stays the same.

I don't know the internals, but the sripts in the web application are working in both situations.
 [2020-06-30 07:25 UTC] cmb@php.net
I think these log entries are from OPcache JIT.  Do you have JIT
enabled (see PHP info)?
 [2020-06-30 09:18 UTC] buschmann at nidsa dot net
I have not changed any configuration for opcache/jit from the proven values of version 7.x.x (for opcache mostly the buffer/string sizes).

JIT seems to be ON by default as is the case here.

Here are the complete config settings from Zend OPcache from phpinfo:
 
Opcode Caching 	Up and Running
Optimization 	Enabled
SHM Cache 	Enabled
File Cache 	Disabled
JIT 	On
Startup 	OK
Shared memory model 	win32
Cache hits 	0
Cache misses 	1
Used memory 	4242384
Free memory 	29312048
Wasted memory 	0
Interned Strings Used memory 	199520
Interned Strings Free memory 	2945736
Cached scripts 	1
Cached keys 	2
Max keys 	983
OOM restarts 	0
Hash keys restarts 	0
Manual restarts 	0 

opcache.blacklist_filename	no value	no value
opcache.cache_id	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.file_cache	no value	no value
opcache.file_cache_consistency_checks	On	On
opcache.file_cache_fallback	On	On
opcache.file_cache_only	Off	Off
opcache.file_update_protection	2	2
opcache.force_restart_timeout	180	180
opcache.interned_strings_buffer	4	4
opcache.jit	1205	1205
opcache.jit_bisect_limit	0	0
opcache.jit_blacklist_root_trace	16	16
opcache.jit_blacklist_side_trace	8	8
opcache.jit_buffer_size	0	0
opcache.jit_debug	0	0
opcache.jit_hot_func	127	127
opcache.jit_hot_loop	64	64
opcache.jit_hot_return	8	8
opcache.jit_hot_side_exit	8	8
opcache.jit_max_loops_unroll	8	8
opcache.jit_max_polymorphic_calls	2	2
opcache.jit_max_recursive_calls	2	2
opcache.jit_max_recursive_returns	2	2
opcache.jit_max_root_traces	1024	1024
opcache.jit_max_side_traces	128	128
opcache.jit_prof_threshold	0.005	0.005
opcache.log_verbosity_level	1	1
opcache.max_accelerated_files	980	980
opcache.max_file_size	0	0
opcache.max_wasted_percentage	5	5
opcache.memory_consumption	32	32
opcache.mmap_base	no value	no value
opcache.opt_debug_level	0	0
opcache.optimization_level	0x7FFEBFFF	0x7FFEBFFF
opcache.preferred_memory_model	no value	no value
opcache.preload	no value	no value
opcache.protect_memory	Off	Off
opcache.record_warnings	Off	Off
opcache.restrict_api	no value	no value
opcache.revalidate_freq	60	60
opcache.revalidate_path	Off	Off
opcache.save_comments	Off	Off
opcache.use_cwd	On	On
opcache.validate_permission	Off	Off
opcache.validate_timestamps	On	On
 [2020-06-30 11:30 UTC] cmb@php.net
> JIT 	On
> opcache.jit_buffer_size	0	0

That looks pretty strange to me.  Would you still get the
"VirtualProtect() failed" errors, if you set
opcache.jit_buffer_size=16M?
 [2020-06-30 13:18 UTC] buschmann at nidsa dot net
When setting opcache.jit_buffer_size=16M and a fresh start the error messages in error.log disappear !!

But I have only  used the defaults, so maybe JIT=On and opcache.jit_buffer_size=0 don't play well together...

BUT: I have also found, that not all opcache config parameters are reported by phpinfo:

In my config file I had set 

opcache.huge_code_pages=1

which is not reported as seen below.

BTW: seems OK with huge_pages=1 in a second test,
BUT in the documentation the flag should be marked as boolean, not string:
(from online manual)

 opcache.huge_code_pages string 

Here are the opcache data from phpinfo after fresh start, scripts reloads and some test with the application, which seems working OK (huge pages disabled for now!):

Opcode Caching 	Up and Running
Optimization 	Enabled
SHM Cache 	Enabled
File Cache 	Disabled
JIT 	On
Startup 	OK
Shared memory model 	win32
Cache hits 	47
Cache misses 	299
Used memory 	22870456
Free memory 	10683976
Wasted memory 	0
Interned Strings Used memory 	2597400
Interned Strings Free memory 	547856
Cached scripts 	299
Cached keys 	538
Max keys 	983
OOM restarts 	0
Hash keys restarts 	0
Manual restarts 	0 

opcache.blacklist_filename	no value	no value
opcache.cache_id	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.file_cache	no value	no value
opcache.file_cache_consistency_checks	On	On
opcache.file_cache_fallback	On	On
opcache.file_cache_only	Off	Off
opcache.file_update_protection	2	2
opcache.force_restart_timeout	180	180
opcache.interned_strings_buffer	4	4
opcache.jit	1205	1205
opcache.jit_bisect_limit	0	0
opcache.jit_blacklist_root_trace	16	16
opcache.jit_blacklist_side_trace	8	8
opcache.jit_buffer_size	16M	16M
opcache.jit_debug	0	0
opcache.jit_hot_func	127	127
opcache.jit_hot_loop	64	64
opcache.jit_hot_return	8	8
opcache.jit_hot_side_exit	8	8
opcache.jit_max_loops_unroll	8	8
opcache.jit_max_polymorphic_calls	2	2
opcache.jit_max_recursive_calls	2	2
opcache.jit_max_recursive_returns	2	2
opcache.jit_max_root_traces	1024	1024
opcache.jit_max_side_traces	128	128
opcache.jit_prof_threshold	0.005	0.005
opcache.log_verbosity_level	1	1
opcache.max_accelerated_files	980	980
opcache.max_file_size	0	0
opcache.max_wasted_percentage	5	5
opcache.memory_consumption	32	32
opcache.mmap_base	no value	no value
opcache.opt_debug_level	0	0
opcache.optimization_level	0x7FFEBFFF	0x7FFEBFFF
opcache.preferred_memory_model	no value	no value
opcache.preload	no value	no value
opcache.protect_memory	Off	Off
opcache.record_warnings	Off	Off
opcache.restrict_api	no value	no value
opcache.revalidate_freq	60	60
opcache.revalidate_path	Off	Off
opcache.save_comments	Off	Off
opcache.use_cwd	On	On
opcache.validate_permission	Off	Off
opcache.validate_timestamps	On	On
 [2020-06-30 14:32 UTC] cmb@php.net
-Package: Apache2 related +Package: opcache
 [2020-06-30 14:32 UTC] cmb@php.net
> When setting opcache.jit_buffer_size=16M and a fresh start the
> error messages in error.log disappear !!

Good news!

> […], so maybe JIT=On and opcache.jit_buffer_size=0 don't play
> well together...

If opcache.jit_buffer_size=0, JIT should be disabled.  I have no
idea why it has been enabled in your case.

> BUT in the documentation the flag should be marked as boolean,
> not string:

Fixed.  Thanks!
 [2020-06-30 15:01 UTC] buschmann at nidsa dot net
When it helps, I can show below all lines from my active php.ini containing "opcache.":


zend_extension = N:\Apache\php8\ext\php_opcache.dll
;zend_extension = N:\Apache\php8\php_opcache.dll
;opcache.enable=0
opcache.enable=1
;opcache.enable_cli=0
;opcache.memory_consumption=64
opcache.memory_consumption=32
;opcache.interned_strings_buffer=4
opcache.interned_strings_buffer=4
;opcache.max_accelerated_files=2000
opcache.max_accelerated_files=980
;opcache.max_wasted_percentage=5
;opcache.use_cwd=1
;opcache.validate_timestamps=1
;opcache.revalidate_freq=2
opcache.revalidate_freq=60
;opcache.revalidate_path=0
;opcache.save_comments=1
opcache.save_comments=0
;opcache.load_comments=1
opcache.load_comments=0
;opcache.fast_shutdown=0
;opcache.fast_shutdown=0
;opcache.enable_file_override=0
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
;opcache.blacklist_filename=
;opcache.max_file_size=0
;opcache.consistency_checks=0
;opcache.force_restart_timeout=180
;opcache.error_log=
;opcache.log_verbosity_level=1
;opcache.preferred_memory_model=
;opcache.protect_memory=0
;opcache.protect_memory=0
opcache.huge_code_pages=1
; http://php.net/opcache.preload
;opcache.preload=
;;opcache.preload="N:\Apache\Apache24\conf\local\php_preload.php"
opcache.jit_buffer_size=16M

This seems to set/change only the following settings:

[opcache]
opcache.enable=1

opcache.memory_consumption=32

opcache.interned_strings_buffer=4

opcache.max_accelerated_files=980

opcache.revalidate_freq=60

opcache.save_comments=0

opcache.load_comments=0

opcache.huge_code_pages=1


opcache.jit_buffer_size=16M

Perhaps this may help to explain where the defaults JIT=ON and jit_buffer_size=0 stem from.

BTW: Do you have an idea with php_info and opcache.huge_code_pages not showing?

In my php.ini I left it on but never confirmed that it worked under windows (it requires OS support, but how exactly ?!?!)

I have managed to activate and verify huge pages usage for Postgres shared buffers on Windows 64bit (by pinning memory with gpedit.msc).

I would like to test JIT with huge pages on on Windows.

Thanks!
 [2020-06-30 21:44 UTC] cmb@php.net
> I would like to test JIT with huge pages on on Windows.

I just learned that these are not supported by PHP on Windows.
 [2020-10-30 08:50 UTC] dominique at ottello dot net
Same errors on Windows with PHP 8.0.0 beta1 to RC3
Apache used as a service and PHP as an Apache module.

opcache is loaded in php.ini by:
[opcache]
zend_extension="E:/wamp64/bin/php/php8.0.0rc3/ext/php_opcache.dll"

Errors occur when using all default opcache directives as they are in the php.ini-development or php.ini-production templates.
 [2020-10-30 10:57 UTC] phpdev at ehrhardt dot nl
@Christoph or @Nikita Is there any change Opcache JIT will be supported on Windows anywhere in the near future?
 [2020-10-30 11:11 UTC] phpdev at ehrhardt dot nl
Or is Opcache JIT only availabke at smaller pages? What is the maximum?
 [2020-11-01 09:26 UTC] dominique at ottello dot net
To avoid these errors under Windows, I added under the [opcache] section of php.ini:
; To avoid errors VirtualProtect() failed [...] Incorrect parameter
opcache.jit=off

It would be nice if in the php.ini-development and php.ini-production files of the php 8 packages for Windows this directive is integrated.

It would be even better if the php.ini-development and php.ini-production files integrate, by default, the appropriate directives so that opcache does not give errors under Windows.
 [2021-03-25 12:01 UTC] wmoreno3 at yahoo dot com
C:\Windows\system32>php -v
PHP 8.0.2 (cli) (built: Feb  3 2021 18:36:40) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies
-----------------------------------------------------------------
; http://php.net/auto-globals-jit
auto_globals_jit = Off
----------------------------------------------------------------
Windows 10 PRO
________________________________________________________________
This setting solved for me this issue
 [2021-04-28 03:10 UTC] yehuda at ymkatz dot net
I can confirm that "auto_globals_jit = Off" fixed it for me. I had hundreds of lines added within seconds of restarting Apache.

Windows 10 Education 20H2 (Build 19042.928)
Apache 2.4.41 (x64) (ApacheLounge)
PHP 8.0.3 Thread Safe x64
 [2021-11-10 18:59 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-11-10 18:59 UTC] cmb@php.net
Has this been resolved in the meantime (possibly by fixing bug
#81206 for PHP 8.0.10)?
 [2021-11-21 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2021-12-01 10:54 UTC] marco at tremani dot nl
I can still reproduce this issue on PHP 8.0.13 and 8.1.0 (with Windows 10 and Apache 2.4.51, all 64 bit)
 [2021-12-01 11:07 UTC] cmb@php.net
-Status: No Feedback +Status: Open -Assigned To: cmb +Assigned To:
 [2021-12-01 11:07 UTC] cmb@php.net
Okay, re-opening then, but without further useful information this
might not be actionable.
 [2022-01-12 07:43 UTC] a_wert_z at gmx dot de
Same here. 
Version: 8.1.1
I came from upgrading a PHP7 installation on Windows tzo PHP8.1
Because of dependencies in the Apace installation I have to use the x32 Version of apache and PHP.
But the problem says the same.

Hundreds of enties in error.log
"VirtualProtect() failed [87] The parameter is incorrect"

opcache was enabled with CLI
opcache.enable=1
opcache.enable_cli=1

disabling opcache solves the issue with the log file, but the performance is much worth than the PHP7 installation
 [2022-02-10 20:55 UTC] schreck06 at aol dot com
$> php -v

PHP 8.1.2 (cli) (built: Jan 19 2022 10:18:23) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
    with Xdebug v3.1.3, Copyright (c) 2002-2022, by Derick Rethans

Windows Server 2022
Build 20348.473

---

When starting the webserver (Apache) the error log is being spammed with:

VirtualProtect() failed [...] Incorrect parameter

---

Solved the issue by adding a line to the php config:

>> php.ini

[opcache]
opcache.jit=off

---

auto_globals_jit=Off

...does result in a performance loss while disabling 'opcache.jit' doesn't noticably
 [2022-07-22 17:01 UTC] php at protopia dot co dot uk
I am also having this issue with "php 8.1.7 win64 vs16" on windows 10 with "apache 2.4.54 win64 vs16".

AFAIK these are both the latest versions.

Disabling JIT does prevent the issue, however this is a workaround not a fix as (presumably) JIT should be working for this combination.
 [2022-12-12 05:50 UTC] pavlusha23 at gmail dot com
In my case, the php_svm extension was to blame. After disabling it, the problem disappeared. opcache.jit works fine after that, but if XDebug is enabled, then opcache.jit is turned off, as described in the documentation.
 [2022-12-12 05:54 UTC] pavlusha23 at gmail dot com
I have this problem on PHP 8.1.12

In my case, the php_svm extension was to blame. After disabling it, the problem disappeared. opcache.jit works fine after that, but if XDebug is enabled, then opcache.jit is turned off, as described in the documentation.

P.S. Test with 8.1.12 TS x64 + Windows 10 Pro 22H2 + php_svm 0.2.3
 [2022-12-27 11:36 UTC] cmswares dot com at gmail dot com
Confirmed on PHP 8.2.0 / Windows 10 (Apache/2.4.48 (Win64) OpenSSL/1.1.1l PHP/8.2.0). Experienced when using default opcache settings. phpinfo() shows `opcache.jit_buffer_size = 0` by default. A setting that isn't present by default in php.ini. When I change that to e.g. 16M from the default 0, the errors in Apache's error.log no longer appear when restarting httpd.

For the record, the error is:

> VirtualProtect() failed [87] The parameter is incorrect 

...and I would get some 450-500 of these entries in one long queue (with no timestamp or other information aside the above line), following:

> [mpm_winnt:notice] [pid 8332:tid 588] AH00354: Child: Starting 500 worker threads.

My production server is running PHP 8.1.4 on Centos 7 and also has the default `opcache.jit_buffer_size = 0`. However, there are no errors on httpd restart. (N.B. I'd love to know if that should be changed or not. Per documentation, 0 disables JIT -- although I still see `opcache.jit tracing`.) 

Then, I assume this is related to the fact that Apache/Windows uses `mpm_winnt` while Linux defauls to `mpm_prefork`, and this issue is specific to mpm_winnt and the instantiation of child workers.
 [2023-10-12 14:44 UTC] personal at rysmax dot com
I was investigating the same case.

I tested CMS EFFCORE on the Windows platform (Windows 10 2021 LTSC x64).

After installing Apache House (httpd-2.4.57-win64-VS17.zip) and PHP (php-8.2.11-vs16-x64.zip), I began to include the missing modules to install the system.

I enabled all the required modules and the system installed without problems.

I ran all the tests and they ran successfully.

Then I decided to speed up the system and enabled OPCache + JIT.

After enabling OPCache + JIT I started getting a "white screen" and the message "virtualprotect() failed 87 the parameter is incorrect".

After disabling OPCache + JIT or OPCache the problem went away.

I was wondering what this error was.

I created a small script and placed it in the "test.php" file.

It had the following contents:

    $path = 'data.php';
    $lines_num = 2000;
    if (!file_exists($path)) {
        file_put_contents($path, '<?php'."\n", FILE_APPEND);
        for ($i = 0; $i < $lines_num; $i++)
            file_put_contents($path, '$data['.$i.'] = \'value '.$i."';\n", FILE_APPEND);
        file_put_contents($path, 'print \'COUNT: \'.count($data);', FILE_APPEND);
        print 'FILE WAS CREATED. RELOAD THIS PAGE';
    } else {
        include_once($path);
        print "\n".'FILE WAS INCLUDED';
    }

Next, I ran “test.php” from the browser and got a white screen if “lines_num” was greater than 2000 and a normal result if less than 2000.
This is an obvious overflow of some memory segment.
However, the log did not contain any information about the error.

From the console I ran this script with any number of "lines_num" and no problems arose.

    php -d opcache.jit_debug=1 test.php
    php -d opcache.jit_debug=1 data.php

I concluded that the problem is with the Apache + PHP combination as a module.
However, there were no problems under Linux/Unix.

Here is the complete list of links:
- win: Apache + PHP as a module - !!! JIT problem !!!
- win: IIS + PHP as FastCGI - OK
- win: PHP CLI - OK
- nix: Apache + PHP as a module - OK
- nix: NGINX + PHP as FastCGI - OK
- nix: PHP CLI - OK

I had to disable OPCache in "php.ini" via "opcache.enable=0" and the problem went away.

In "php.ini" you can disable only JIT via "opcache.jit_buffer_size=0" but this setting cannot be changed directly from PHP code.

Changing other "opcache.*" settings in "php.ini" did not lead to anything.

You can also disable OPCache + JIT programmatically with the following code:

     if (DIRECTORY_SEPARATOR === '\\') {
         ini_set('opcache.enable', false);
     }

Thank you for your attention, I hope it helped.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC