PHP opcache导致函数失败

时间:2018-05-07 01:28:17

标签: php nginx opcache

情况如何?

  • 2个网站: A B (laravel5.2)
  • A 想要使用 B javascript档案
  • B 正在使用opcache
  • B 使用git更新代码和post-hook请求指定URL重置opcache

网站A代码:

<script src="https://B/controller/getJsFunction"></script>

网站B代码:

public function getJsFunction()
{
    header('Content-Type:application/javascript');
    header('Cache-Control: max-age=0, must-revalidate');
    //mix('/js/visitor.js') will get visitor.js and auto add the current version
    echo file_get_contents(rtrim(public_path(), '/') . mix('/js/visitor.js'));
}

我想要什么?

  • 网站 A 获取网站 B javascript文件内容
  • B 可以随时升级javascript文件版本号,visitor.v1.js =&gt; visitor.v2.js

发生了什么事?

经过一段成功的操作后,

B 维持返回502 HTTP状态代码, 当 B 修改任何代码触发器opcache_reset()时,即使只是添加评论,bug也会修复一段时间。

我有什么?

nginx日志

2018/05/06 03:56:17 [error] 12747#0: *28155344 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xxxxxxx, server: xxxxxxx.com, request: "GET /stateless/visitor/js HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxx.com", referrer: "https://xxxxxx"

git收到后

cd /path/to/site-B/project
unset  GIT_DIR
git pull origin master && curl https://site-B.com/cache.php 

cache.php

<?php
opcache_reset();

nginx.conf

user  nginx nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log  error;

pid        /var/run/nginx.pid;

events {
    use epoll;
    worker_connections 1024;
}

http {
    include         /etc/nginx/black.ip;
    include         /etc/nginx/mime.types;
    default_type    application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;

    keepalive_timeout   600;
    fastcgi_read_timeout 600;
    types_hash_max_size 2048;
    client_max_body_size 20m;

    gzip                on;
    index       index.html index.htm index.php;

    server {
        listen 80 default;
        server_name _;
        return 403;
    }

    server {
        listen       80;
        listen       443;
        server_name  site-b.com;
        root         /path/to/site-b.com/public;

        ssl on;
        ssl_certificate /path/to/site-b.com.crt;
        ssl_certificate_key /path/to/site-b.com.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;

        if ($scheme = http ) {
            rewrite ^(.*)$ https://$host$1 permanent;
        }

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~* \.(jpg|jpeg|png|gif|js|css|ico|eot|svg|ttf|woff|woff2)$ 
        {
            expires max;
            add_header Cache-Control public;
            add_header Pragma public;
            add_header Vary Accept-Encoding;
        }

        location ~* \.php$ {
            try_files $uri =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME
                           $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

}

我需要什么帮助?

  • 如何真正修复错误?
  • 或者我应该使用其他什么方法?
  • 为什么reset_opcache()可以修复错误?或者为什么opcache会导致此错误?

由于这是一个在线项目,我暂时将其修改为网站A 首次请求网站B 以获取{{1}的当前版本}文件,然后插入javascript代码并从第一步回复设置script网址

0 个答案:

没有答案