Moodle crashes when enabling opcache

Moodle crashes when enabling opcache

by Nick Varney -
Number of replies: 11

Windows 2008 R2 VM

IIS 7

MOODLE 2.6.11


I'm trying to perform a PHP upgrade from 5.4.1 to 5.6.14

Upgrading using PHP Manager for IIS.

Registering the new version of PHP in PHP Manager is fine.

As soon as I include the line zend_extension=php_opcahe.dll or the specific path to opcache zend_extension=E:\php\ext\php_opcache.dll I get a 500 internal server error. If I comment this line out Moodle is fine and phpinfo shows that the new version of PHP is running but without Opcache.

The confusing thing is that I have successfully performed the PHP upgrade with opcache enabled on two clones of this server.

It's not the dll itself as the same error occurs on php 5.6 and 5.6.10.

PHP has been unable to create an error log which is odd? Does that point to an issue with permissions??

All I have been able to get in terms of information is the following error notification when I try and view phpinfo via PHP Manager with the zend_extension line in php.in active.

The physical path to an obsurely named php file in my Moodle root looks most odd - that file definitely does not exist.


Screenshot:

phpinfo image


Any ideas or things to try appreciated.

Average of ratings: -
In reply to Nick Varney

Re: Moodle crashes when enabling opcache

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you Google "iis7 opcache error 500" there are lots of similar sounding reports. Non (that I could find) sounding like they had a terribly satisfactory solution. 

I'm not a Windows person, but a good start would be to make sure everything possible is bumped up to the latest version. 

In any case, unless your site has a great deal of load OpCache doesn't make a huge difference for most people. If it works ok, leave it switched off. 

Average of ratings: Useful (1)
In reply to Nick Varney

Re: Moodle crashes when enabling opcache

by Usman Asar -
Picture of Plugin developers Picture of Testers

Nick, it would be IIS 7.5 with R2, now coming  to your part, have you rechecked the php configuration file? as I have had no issues running Opcache on IIS 8.5 with Server 2012 R2 using PHP 5.6 and as well PHP 7.0 (Alpha).

Average of ratings: Useful (1)
In reply to Usman Asar

Re: Moodle crashes when enabling opcache

by Nick Varney -

Yes you're right, I'm running IIS 7.5.

I believe my .ini file has everything correctly placed. It has the zend_extension=php_opcache.dll after the list of extensions as directed - however the inclusion of this line is causing the problem.

I then have the recommended Opcache directives that have been provided on Moodle's opcache instructions i.e.


[opcache]

opcache.enable = 1

opcache.memory_consumption = 128

opcache.max_accelerated_files = 4000

opcache.revalidate_freq = 60

 

; Required for Moodle

opcache.use_cwd = 1

opcache.validate_timestamps = 1

opcache.save_comments = 1

opcache.enable_file_override = 0


I then began to uncomment the additional lines provided in the Moodle opcache guide to no avail...


; If something does not work in Moodle

;opcache.revalidate_path = 1 ; May fix problems with include paths

;opcache.mmap_base = 0x20000000 ; (Windows only) fix OPcache crashes with event id 487

 

; Experimental for Moodle 2.6 and later

;opcache.fast_shutdown = 1

;opcache.enable_cli = 1 ; Speeds up CLI cron

;opcache.load_comments = 0 ; May lower memory use, might not be compatible with add-ons and other apps.


In my two test sandboxes I have been successful in getting opcache running. When I use a .ini file from one of these instances where opcache  on my production Moodle site it crashes and only comes back up when I remove the zend_extesnion=php_opcache.dll line.


On one of my sandboxes the additional instructions for opcache, including opcache.enable, remains commented out and still zend_opcache shows as running in php.info? Does opcache run with a set of default settings and are only changed if specified in the .ini? Anyway I'm at a loss as to why the same php upgrade is failing at this point on my production server when it has been successful on the sandboxes which are clones of the production server.


In reply to Nick Varney

Re: Moodle crashes when enabling opcache

by Usman Asar -
Picture of Plugin developers Picture of Testers

Nick, I have been using these settings and working fine for me


[ExtensionList]

zend_extension=php_opcache.dll

[opcache]
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1


Just make sure you dont have another cache installed and running, like for example you may have turned on WinCache, as that is the cache engine coming with IIS and PHP developers together with IIS have worked on it well to make it better since IIS 8, but when it comes to Moodle, I have tested both and both works neck to neck with OpCache working slightly better than winCache.

Average of ratings: Useful (1)
In reply to Usman Asar

Re: Moodle crashes when enabling opcache

by Nick Varney -

Finally stumbled upon some definite error messages in the Application Event log to do with ZendOpcache_Memory Base

C:\Windows\TEMP\ZendOpcache.MemoryBase@DefaultAppPool

Access is denied


Plus

Unable to write base address

Access is denied


ZendOpcache_Memory Base 1


ZendOpcache_Memory Base 2


Have read that I can get around this by determining a memory segment via opcache.mmap_base in php.ini. I tried this with a 64 bit value  of 0x0000200000000000 to no avail.

I understand this has to do with PHP needing to write to the same bit of memory space and that opcache.mmap is attempting to specify the segment of memory that opcahe can write to. It would appear however that the zendopcache user (the username of which I have worked out) does not have the correct permissions on my server. I am unsure how to change this.

Given the hassle this has been to set up I may take Howard's advice and not bother with opcache! But getting user permissions correctly in place will be important I feel - currently the php error log is being written so I suspect that is also permissions related.


In reply to Nick Varney

Re: Moodle crashes when enabling opcache

by Nick Varney -

That last line should have read that 'currently the php error log is not being written...'

In reply to Nick Varney

Re: Moodle crashes when enabling opcache

by Usman Asar -
Picture of Plugin developers Picture of Testers

Nick, just to be assured as I haven't had any troubles with zend opcache on my testings of IIS, are you using the Non-thread safe version of PHP?

With regards to 32 and 64 bit, though I have done testing on 64 bit despite it's in development but is coming fully operational with PHP 7, so are you using 32 or 64-bit version?

In reply to Usman Asar

Re: Moodle crashes when enabling opcache

by Nick Varney -

Yes can confirm I'm using the 32 bit NTS version of PHP.

As I was able to get Opcache working on two test servers I'm convinced this problem is something to do with user permissions on my production server as PHP is also unable to create and write an error log.

In reply to Nick Varney

Re: Moodle crashes when enabling opcache

by Usman Asar -
Picture of Plugin developers Picture of Testers

have you given permissions to user "IUSR_IIS" whole inetpub directory?

This is what is recommended when configuring IIS, though just wwwroot would have been sufficient, but as moodledata folder is placed outside of wwwroot, similar permissions are to be given to that whole folder.

In reply to Usman Asar

Re: Moodle crashes when enabling opcache

by Doan Dung -

I want reinstall my moodle, without opcache, then can my moodle work?

In reply to Doan Dung

Re: Moodle crashes when enabling opcache

by Usman Asar -
Picture of Plugin developers Picture of Testers

Doan, of course it will work without OpCache as well, but turning it ON will make your pages render faster requiring less memory to perform tasks as well, btw, which server you have?