Search code examples
phpfacebooknginxyii2fpm

Yii2 Facebook auth success once after PHP restarts, fails afterwards


I'm using facebook login on my Yii2 app by following this tutorial: https://mushtaqtahir.com/blog/2/facebook-authentication-using-yii2-authclient

It works without problems for months, but suddenly a problem occured. When I try to login, it give error 502 after succesfully logged in on Facebook and return to the app. I try to restart PHP FPM on the server. It works just once after PHP restarted, but continue to fail afterwards.

I check nginx error log and found this:

2017/05/31 05:49:30 [error] 7368#7368: *151 recv() failed (104: Connection reset by peer) 
while reading response header from upstream, client: 103.47.104.104, server: my.app, request: 
"GET /site/auth?authclient=facebook&code=AQA5h_.....gIdRKg&state=6a424...7efc 
HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "my.app"

What might be the problem?


Solution

  • Solved it! Thanks to @vijay-nathji who pointed in the right direction!

    This is actually a bug in PHP 7 (Bug #73310 PECL OAuth segfaults when OPcache is enabled in PHP 7). This problem should be fixed in PHP 7.1.3, but I need a quick solution.

    So what I did is disabled OPC only on the specific function that handle the Facebook login. I add on the frontend/config/main.php :

    'on beforeRequest' => function(){
        if(strpos($_SERVER['REQUEST_URI'], 'auth') !== false){
            ini_set('opcache.enable', false);
        }
    },