PHP speed optimization

I'm curious about speed optimization in PHP.

I have a series of files that are requested when each page loads. An average of 20 files. Each file must be read parsed if they have been modified. And this excludes the standard files needed for a web page (HTML, CSS, images, etc.).

EG → page of client requests → server outputs html, css, images → server displays dynamic content (20 +/- files are combined and reduced).

What would be the best way to serve these files as quickly as possible?

+3
source share
4 answers

, profiling, :

  • , - .
  • - , " " , , .

, , .

+4

, . , - , , , - , , ( URL-), ( ) .

, . 20 .

php? HTML-?

,

, ? ? , , , .

? :

<?php

    $cached=md5($_SERVER['REQUEST_URI']);
    $lastmod=time() - @mtime($cache_dir . $cached)
    if ((file_exists($cache_dir . $cached)) && (60 < $lastmod)) {
       print file_get_contents($cache_dir . $cached);
       exit;
    } else {
       ob_start();
   ... do slow expensive stuff
       $output=ob_get_contents();
       print $output;
       file_put_contents($output, $cache_dir . $cached);
    }
?>

, , .

, , - - , , , .

.

.

+1

PHP, eAccelerator. , mmtime, , , .

, yslow, , .

0

PHP, . APC - , .

0

Source: https://habr.com/ru/post/1750476/


All Articles