PHPエコー関数は1秒以上実行できます

または、PHPのコンテンツ管理の機能について。



この記事の理由は2日間の調査であり、その結果は、無害なパフォーマンスエコーおよび印刷機能実際に非常に長期間動作し、そのパフォーマンスがエンドユーザーのインターネットの品質に依存することを示しました。



そもそも、昨日これを言われたら、この人の神殿の周りに指をひねっていただろうが、一連のテストは容赦なくこれを証明している。







ページ生成:強力なサーバーで1秒、200ミリ秒。 弱い人に。



それはすべて、 CakePHPフレームワークに自己記述プロファイラを実装し、コードの主要な論理部分の後の実行間隔を計算する機能を組み込んだという事実から始まりました。 すべてがローカルサーバーで正常に機能し、プロファイラーは200〜300ミリ秒を示しました しかし、本番環境では(サーバーははるかに強力で、訪問者にまだ追いついていません)、実行時間は1〜3秒でした。



お気に入りのデバッグ方法を使用して:

  1. $microtime = microtime(true);
  2. //
  3. echo (microtime(true) - $microtime);






, :

  1. print $out;






.



, , 6 PHP. , , 11-32 .

Nagle algorithm, . -, Apache. .



.



, , :

  1. $index = !empty($_GET['index']) ? $_GET['index'] : 1;
  2. $example_output = str_repeat(str_repeat("*", 1024), $index);
  3.  
  4. $microtime = microtime(true)*1000;
  5. echo $example_output;
  6. $interval = microtime(true)*1000 - $microtime;
  7.  
  8. echo '<br>Display Length: ', $index, ' KiB.<br>';
  9.  
  10. if($interval < 100 && $_GET['index'] < 100)
  11.   echo '<meta http-equiv="refresh" content="1; url=?index='.($index + 1).'" />';
  12.  
  13. echo 'Reach end file: ', round($interval, 2), ' ms.'."<br>\n";






, , , echo 100 .



, 11 :

*****

Display Length: 11 KiB.

Reach end file: 0.07 ms.









12 :

*****

Display Length: 12 KiB.

Reach end file: 348.92 ms.









. — 13 . ( ) — .



, 348.92 ms , , , .



.



, PHP.

, :

PHP good output buffering

:



:

1. .

2. Apache`.

3. PHP.

4. echo, PHP .

5. Apache .

6. PHP shutdown . , register_shutdown_function.

7. . .

8. PHP ( session_write_close).

9. Apache .

10. .



:

PHP output buffering problems

:

4a. echo. Apache.

4b. Apache , , echo.

8a. PHP , , .

8b. Apache .

8c. PHP .



4 , . , PHP .



.



PHP, « » , output_buffering=200K .



, . PHP:



, . . output_buffering , PHP shutdown , .

:

php_value output_buffering 131072





, - , . :

php_flag output_buffering On







«» :

PHP output buffering problem solution

, :





.



, , echo. , , , 11 PHP . , 18 .



.



1984 Nagle, PHP . , , .



.



, .

. . , wget, 128 .

wget --limit-rate=1K www.test.lo/nagle_test.php?index=128

Display Length: 128 KiB.

Reach end file: 57234.61 ms.









, :




All Articles