Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Debug and Log PHP OPcache Issues

I am using WAMP on Windows 10, running PHP 7.2 with Apache 2.4

When I am turning on OPcache, a page I am loading crashes with the following error in Chrome:

ERR_CONNECTION_RESET

I checked the php error log and Apache error log and could not find any error reported. I tried to disable Xdebug, still same crash and no errors in the logs. Turning off OPcache or switching to php 7.1 or below resolves the issue.

I was looking everywhere for some information on how to debug what causes OPcache to fail (and the reason) as turning it off is not a solution, but couldn't find anything helpful (also checked similar SO questions like this one which also has no resolution), so I am reaching out to the experts here for assistance, which I am sure will also help others.

Thank you.

P.S. Note that after a very long manual trial and error I was able to find the file in my php application that was causing OPcache to fail/crash and blacklisted that file in OPcache php.ini configuration (also reducing its size worked fine, so I doubt the problem was the actual code inside), but I am still looking for an easy way to debug such issues without having to go through & check each file on a server. I also don't know why it fails, so finding the cause for the failure will help file bug reports to the OPcache developers.

EDIT: Adding a pastebin link requires code to be added to the question. Here is the beginning of the pastebin file:

<?php

global $_LANGADM;
$_LANGADM = array();

$_LANGADM['AdminAddressesd3b206d196cd6be3a2764c1fb90b200f'] = 'Delete selected';
$_LANGADM['AdminAddressese25f0ecd41211b01c83e5fec41df4fe7'] = 'Delete selected items?';

TL;DR

I am looking for:

1) A way to easily determine that OPcache is the extension that makes a script fail, without having to go through each extension with a manual trial and error (turn them on/off until finding the extension that fails).

2) Easily find a way/log that shows which file and the reason/s it fails when OPcache is enabled.

In simplest words - how can we know when, where and why OPcache fails when it fails, as without any reports/logs it's like searching for a needle in a haystack, especially when even Xdebug seems to be not logging or outputing anything when OPcache fails, for some reason.

Thanks again

like image 954
Nikita 웃 Avatar asked Aug 31 '18 07:08

Nikita 웃


People also ask

Is Opcache enabled in PHP?

Also, your opcache is indeed enabled, but only for web, not cli. The default for the library is enabled for web so , to disable uncomment the line starting with a semicolon like this: As noted, for command line php use, the default is disabled, to enable it, uncomment and set to 1

What is Opcache_get_configuration () function in PHP?

Note: This operator is known by the veteran PHPers as the STFU operator. opcache_get_configuration () Function: This function is used to get the configuration information about the cache. This function returns configuration data about the cache instance and also returns an array of information including the ini file.

What is debug logging in PHP and how to use it?

Sometimes this means doing a var_dump or logging a whole series of events. It’s useful to have debug logging in your program. In PHP, you can use various loggers to log debug messages. When the program is run in debug mode or the log level is set to debug, these messages will end up in your stdout, stderr, or log files.

What is the error log for Opcache?

The error log for OPcache errors. An empty string is treated the same as stderr, and will result in logs being sent to standard error (which will be the Web server error log in most cases). The log verbosity level. By default, only fatal errors (level 0) and errors (level 1) are logged.


1 Answers

1) A way to easily determine that OPcache is the extension that makes a script fail, without having to go through each extension and turn them on/off until finding the extension that fails.

You can add the following to your script to temporarily disable opcache.

ini_set('opcache.enable', 0);

2) Easily find a way/log that shows which file and the reason/s it fails when OPcache is enabled.

This is harder without more information about the application you are trying to debug. You can start by ensuring your error display is turned on.

ini_set('display_errors', 1); error_reporting(~0);

However, if that doesn't work I would suggest debugging your application with Xdebug.

Xdebug's (remote) debugger allows you to examine data structure, interactively walk through your and debug your code (from https://xdebug.org/docs/remote).

like image 69
George Avatar answered Oct 20 '22 12:10

George