Search code examples
phplaravel-5.3

Is this caused by opcache error?php-fpm execute code out of date


Today I meet a strange question:

our project need to online a new module

when I execute artisan down in online environment and visit the site, I found it isn't show the maintenance page, it also show the home page

I check the CheckForMantenance Middleware has aleady add to global route middleware, the down file in storage/framework is exist

I execute php index.php it return the maintenance page, but When I visit the site from brown or curl it show the home page

I also run in test server and local, it all work well

I add a new route for test middlware, and visit the url used by curl and brown, and result is 404, the route does not found

I think it may be caused by router cache, but there is no cache file on bootstrap/cache or storage/framework, because I never open router cache!

I have no idea, so I modify the index file, add write header function at top, and redirect to a error html, the crazy thing happened it also show the home page!!!!!!

What happend? I'm sure the project path is right

Finally I reload the php-fpm and it recovery normal, the maintenance view work, redirect url work, and route normal

I don't understand still now, but I guess it may by caused by opcache?

I open the opcache ext, and use the default setting;

env:

laravel: 5.3 
nginx: 1.8.1
php-fpm: 7.0.9 with opcache ext

Solution

  • First check your fpm logs, usually, something like this will pop up (check debug/log levels) between the notices:

    [01-Mar-2017 23:59:45] NOTICE: [pool www] child 16951 started
    [01-Mar-2017 23:59:48] WARNING: [pool www] child 14754 
      exited on signal 11 (SIGSEGV - core dumped) after 4393.427133 seconds 
      from start
    

    You have to disable opcache unfortunately. I've been seeing this issue since php 5.5 all the way to 7.1 , you will also find these in the error logs:

    2017/03/02 10:00:24 [error] 30498#30498: *170523 upstream timed out    
       (110: Connection timed out) while reading response header from upstream, 
       client: 81.243.144.1xx, server: fake.test.pro, 
       request: "POST /api/users/53e4203cfd1c46e08d5b570c2c93ff86/items HTTP/1.1", 
       upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "fake.test.pro", 
       referrer: "http://fake.test.pro/console"
    

    In particular with Laravel, but I've also seen it on wordpress installations. It stops when I disable opcache on all versions of php-fpm

    There are bugreports around on this issue but no fixes so far. I always end up doing this :

    [opcache]
    ; Determines if Zend OPCache is enabled
    opcache.enable=0
    

    in /etc/php/7.*/fpm/php.ini files. Then my application is robust again and it costs us 150ms. it sucks.