realpathキャッシュと OPcacheの面倒すぎる関係

697 views

Published on

第七回闇PHP勉強会 (2016/12/11) 発表資料

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
697
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

realpathキャッシュと OPcacheの面倒すぎる関係

  1. 1. ❖ ❖ ❖ ❖
  2. 2. ❖ ❖
  3. 3. ❖ ❖ 
 

  4. 4. ❖ ❖ ❖ ❖ ❖
  5. 5. ❖ ❖ ❖ ❖ ❖
  6. 6. ❖ *.php ❖ ❖ ❖ ❖
  7. 7. <?php require_once("/foo/bar/baz.php"); require_once("bar/baz.php"); require_once("baz.php"); ❖ ❖ ❖
  8. 8. ❖ *.php ❖
  9. 9. switch (type) { case ZEND_INCLUDE_ONCE: case ZEND_REQUIRE_ONCE: { zend_file_handle file_handle; zend_string *resolved_path; resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename)); if (resolved_path) { if (zend_hash_exists(&EG(included_files), resolved_path)) { goto already_compiled; } Zend/zend_execute.c zend_include_or_eval()
  10. 10. switch (type) { case ZEND_INCLUDE_ONCE: case ZEND_REQUIRE_ONCE: { zend_file_handle file_handle; zend_string *resolved_path; resolved_path = zend_resolve_path(Z_STRVAL_P(inc_filename), (int)Z_STRLEN_P(inc_filename)); if (resolved_path) { if (zend_hash_exists(&EG(included_files), resolved_path)) { goto already_compiled; } Zend/zend_execute.c zend_include_or_eval()
  11. 11. ❖ *.php ❖ stat(2) ❖ stat ❖
  12. 12. ❖ ❖ ❖ $ pstree 35811 -+= 35811 hnw sapi/fpm/php-fpm |--- 35812 hnw sapi/fpm/php-fpm --- 35813 hnw sapi/fpm/php-fpm
  13. 13. ❖ ❖ ❖ $ pstree 35811 -+= 35811 hnw sapi/fpm/php-fpm |--- 35812 hnw sapi/fpm/php-fpm --- 35813 hnw sapi/fpm/php-fpm
  14. 14. ❖ *.php ❖ stat(2) ❖ ❖ ❖
  15. 15. ❖ ❖ ❖ ❖ ❖
  16. 16. !"" current -> /var/www/my_app_name/releases/20150120114500/ !"" releases # !"" 20150100093500 # !"" 20150110104000 # $"" 20150120114500 ❖ ❖
  17. 17. ❖ ❖ *.php ❖ ❖ ❖ ❖
  18. 18. ❖ *.php ❖ *.php ❖ *.php ❖ ❖
  19. 19. ❖ realpath_cache_ttl ❖ ❖ *.php ❖ ❖ ❖ realpath_cache_ttl=0
  20. 20. ❖ ❖ *.php ❖ ❖
  21. 21. ❖ ❖ ❖ ❖ ❖
  22. 22. ❖ ❖ *.php ❖ ❖ ❖
  23. 23. ❖ ❖ ❖ 
 ❖
  24. 24. ❖ ❖ ❖
  25. 25. ❖ opcache.revalidate_path=0 ❖ ❖ ❖ ❖
  26. 26. ❖ ❖ ❖ int main(int argc, char *argv[]) { /* */ php_execute_script(&file_handle); sapi/fpm/fpm/fpm_main.c sapi/apache2handler/sapi_apache2.c
  27. 27. typedef struct _zend_file_handle { union { int fd; FILE *fp; zend_stream stream; } handle; const char *filename; zend_string *opened_path; zend_stream_type type; zend_bool free_filename; } zend_file_handle; ❖
  28. 28. typedef struct _zend_file_handle { union { int fd; FILE *fp; zend_stream stream; } handle; const char *filename; zend_string *opened_path; zend_stream_type type; zend_bool free_filename; } zend_file_handle; ❖
  29. 29. ❖ php_execute_script() 
 file_handle->opened_path ❖ ❖
  30. 30. ❖ file_handle->opened_path do_validate_timetamps() ❖ ❖ ❖ opcache.validate_timestamps=1
  31. 31. ❖ ❖ ❖ ❖
  32. 32. ❖ opcache.revalidate_path=0 ❖ ❖ opcache.revalidate_path=1 ❖ ❖ ❖
  33. 33. ❖ ❖ ❖ ❖ ❖
  34. 34. ❖ ❖ ❖ ❖ ❖
  35. 35. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; ❖ ❖ $realpath_root ❖
  36. 36. ❖ ❖ ❖
  37. 37. ❖ ❖ ❖ ❖
  38. 38. ❖ ❖ ❖ opcache.revalidate_path=0 ❖ ❖ ❖
  39. 39. ❖ ❖ ❖ ❖ ❖
  40. 40. ❖ ❖ ❖ ❖ ❖
  41. 41. ❖ opcache.max_accelerated_files ❖ ❖ ❖ opcache_get_status()
  42. 42. ❖ opcache.max_wasted_percentage ❖ ❖ ❖ ❖
  43. 43. ❖ ❖ ❖ ❖ ❖
  44. 44. ❖ opcache_invalidate($script) ❖ ❖ ❖ opcache_reset() ❖
  45. 45. ❖ ❖ ❖ $realpath_root opcache_invalidate() ❖ ❖ ❖
  46. 46. ❖ ❖ opcache.revalidate_path=1 ❖ realpath_cache_ttl=5 ❖ ❖ opcache.revalidate_path=0 ❖ opcache.validate_timestamps=0
  47. 47. ❖ ❖ ❖ ❖ opcache_reset()
  48. 48.
  49. 49. <?php define('ROOT_DIR', getcwd()); /* dirname(__FILE__) */ /* autoloader */ ❖ ❖ ❖ ❖

×