2014-05-19 27 views
18

Tôi đang cố gắng đặt lại opcache PHP sau khi triển khai kiểu liên kết tượng trưng. Có file opcache_reset.php trong dự án của tôi được thực hiện bởi wget sau khi thay thế liên kết tượng trưng gốc tài liệu của:PHP opcache reset + triển khai kiểu liên kết tượng trưng

<?php 
clearstatcache(true); 
opcache_reset(); 

Mặc dù vậy, các file cũ vẫn được sử dụng. Theo đầu ra opcache_get_status(), số lượng tăng manual_restarts, last_restart_time giữ cập nhật, nhưng đường dẫn tệp vẫn lỗi thời. Tôi cần gọi opcache_reset.php theo cách thủ công sau một phút hoặc lâu hơn sau khi triển khai để thực hiện đúng.

Phiên bản PHP là 5.5.6, ZendOpcache là 7.0.3-dev. Opcache config:

opcache.blacklist_filename => no value 
opcache.consistency_checks => 0 
opcache.dups_fix => Off 
opcache.enable => On 
opcache.enable_cli => On 
opcache.enable_file_override => Off 
opcache.error_log => no value 
opcache.fast_shutdown => 1 
opcache.force_restart_timeout => 180 
opcache.inherited_hack => On 
opcache.interned_strings_buffer => 8 
opcache.load_comments => 1 
opcache.log_verbosity_level => 1 
opcache.max_accelerated_files => 4000 
opcache.max_file_size => 0 
opcache.max_wasted_percentage => 5 
opcache.memory_consumption => 128 
opcache.optimization_level => 0xFFFFFFFF 
opcache.preferred_memory_model => no value 
opcache.protect_memory => 0 
opcache.restrict_api => no value 
opcache.revalidate_freq => 60 
opcache.revalidate_path => Off 
opcache.save_comments => 1 
opcache.use_cwd => On 
opcache.validate_timestamps => On 

Trả lời

37

Lý do và hai giải pháp có thể được mô tả trong ZendOptimizerPlus issue. Chúng tôi giải quyết nó bằng cách sử dụng $realpath_root trong cấu hình nginx:

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 
fastcgi_param DOCUMENT_ROOT $realpath_root; 
+1

Tôi đang sử dụng các chỉ thị nginx cùng. Tuy nhiên, tôi cần phải tải lại php fpm để đảm bảo rằng php fpm sử dụng mã từ thư mục mới. Tải lại fpm khiến tôi mất một số yêu cầu. Nếu tôi không tải lại fpm, thì nó vẫn thực thi mã trong thư mục cũ. Vấn đề tương tự được mô tả tại đây: http://serverfault.com/questions/630573/atomic-deployments-with-nginx-and-php-fpm Bạn có thể trợ giúp không? –

0

Tôi cũng phải đối mặt với vấn đề đó rồi cuối cùng tôi thực hiện một giải pháp.

$ curl -sO http://gordalina.github.io/cachetool/downloads/cachetool.phar 
$ chmod +x cachetool.phar 

Bạn có thể kết nối đến một máy chủ fastcgi tự động đoán (nếu /var/run/php5-fpm.sock là một tập tin hoặc 127.0.0.1:9000)

apc 
    apc:bin:dump    Get a binary dump of files and user variables 
    apc:bin:load    Load a binary dump into the APC file and user variables 
    apc:cache:clear   Clears APC cache (user, system or all) 
    apc:cache:info   Shows APC user & system cache information 
    apc:cache:info:file  Shows APC file cache information 
    apc:key:delete   Deletes an APC key 
    apc:key:exists   Checks if an APC key exists 
    apc:key:fetch   Shows the content of an APC key 
    apc:key:store   Store an APC key with given value 
    apc:sma:info    Show APC shared memory allocation information 
opcache 
    opcache:configuration Get configuration information about the cache 
    opcache:reset   Resets the contents of the opcode cache 
    opcache:status   Show summary information about the opcode cache 
    opcache:status:scripts Show scripts in the opcode cache 

Ví dụ:

[[email protected] ~]# php cachetool.phar opcache:status 
+----------------------+---------------------------------+ 
| Name     | Value       | 
+----------------------+---------------------------------+ 
| Enabled    | Yes        | 
| Cache full   | No        | 
| Restart pending  | No        | 
| Restart in progress | No        | 
| Memory used   | 42.71 MiB      | 
| Memory free   | 85.29 MiB      | 
| Memory wasted (%) | 0 b (0%)      | 
| Strings buffer size | 8 MiB       | 
| Strings memory used | 5.31 MiB      | 
| Strings memory free | 2.69 MiB      | 
| Number of strings | 103847       | 
+----------------------+---------------------------------+ 
| Cached scripts  | 1261       | 
| Cached keys   | 2748       | 
| Max cached keys  | 7963       | 
| Start time   | Thu, 08 Feb 2018 02:28:56 +0000 | 
| Last restart time | Thu, 08 Feb 2018 03:10:19 +0000 | 
| Oom restarts   | 0        | 
| Hash restarts  | 0        | 
| Manual restarts  | 1        | 
| Hits     | 47839       | 
| Misses    | 1269       | 
| Blacklist misses (%) | 0 (0%)       | 
| Opcache hit rate  | 97.415899649752     | 
+----------------------+---------------------------------+ 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# php cachetool.phar opcache:reset 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# php cachetool.phar opcache:status 
+----------------------+---------------------------------+ 
| Name     | Value       | 
+----------------------+---------------------------------+ 
| Enabled    | Yes        | 
| Cache full   | No        | 
| Restart pending  | No        | 
| Restart in progress | No        | 
| Memory used   | 10.43 MiB      | 
| Memory free   | 117.57 MiB      | 
| Memory wasted (%) | 0 b (0%)      | 
| Strings buffer size | 8 MiB       | 
| Strings memory used | 545.69 KiB      | 
| Strings memory free | 7.47 MiB      | 
| Number of strings | 103847       | 
+----------------------+---------------------------------+ 
| Cached scripts  | 0        | 
| Cached keys   | 0        | 
| Max cached keys  | 7963       | 
| Start time   | Thu, 08 Feb 2018 02:28:56 +0000 | 
| Last restart time | Thu, 08 Feb 2018 03:19:00 +0000 | 
| Oom restarts   | 0        | 
| Hash restarts  | 0        | 
| Manual restarts  | 2        | 
| Hits     | 0        | 
| Misses    | 2        | 
| Blacklist misses (%) | 0 (0%)       | 
| Opcache hit rate  | 0        | 
+----------------------+---------------------------------+ 

Bạn có thể nhận thấy rằng bộ nhớ, các phím bộ nhớ cache, số lần truy cập đã trở thành 0 :-). Nó rất hữu ích. Tôi cũng hấp dẫn nó với Ansible dễ dàng.

ứng dụng của nó đối với apcu và những người khác chất liệu: Kiểm tra càng có http://gordalina.github.io/cachetool/

Các vấn đề liên quan