1

When a client request a page which contains some php functions, say functions.php, the server processes the file and presents the page. If a second user request the same page, does, or can the web server share a cached version, or anything of that sort with the second user?

User 1 -> index.php -> includes -> functions.php

Server <- functions.php

User 2 -> index.php -> includes -> functions.php

Server <- cached functions.php

Or, will the server ALWAYS process a new version on request?

Joe Swindell
  • 684
  • 1
  • 7
  • 18
  • That's up to how your code is written. – Mike B Nov 10 '14 at 16:49
  • 3
    Servers can be configured to store php files as bytecode in their RAM thus serving these scripts faster. An easy way to achieve this is by installing/enabling APC or using [PHP's opcode](http://stackoverflow.com/questions/17224798/how-to-use-php-opcache) – DarkBee Nov 10 '14 at 16:49
  • 2
    Without any kind of PHP opcode cache (e.g. APC), the only thing cached between requests is the code of the php script in the server's disk cache. Every PHP request is basically completely independent of every other request. Two different requests for the same script will trigger two different compilation/execution phases of the same code. – Marc B Nov 10 '14 at 16:52
  • This question has been answered here: http://stackoverflow.com/questions/3787125/how-to-cache-dynamic-php-page – Len_D Nov 10 '14 at 16:52
  • possible duplicate of [How To Implement A PHP/HTML Cache](http://stackoverflow.com/questions/829126/how-to-implement-a-php-html-cache) – dynamic Nov 10 '14 at 16:55
  • @MarcB Could you put that as an answer. That's exactly the information I was looking for. – Joe Swindell Nov 10 '14 at 16:58

1 Answers1

2

Without any kind of PHP opcode cache (e.g. APC), the only thing cached between requests is the code of the php script in the server's disk cache. Every PHP request is basically completely independent of every other request.

Two different requests for the same script will trigger two different compilation/execution phases of the same code.

Marc B
  • 356,200
  • 43
  • 426
  • 500