Lots of php files or one big php file

偶尔善良 提交于 2019-12-12 06:57:31

问题


I want to know which approach is better in terms of speed and performance when the site has millions of users making millions of requests per day.

What is the matter ? - thousands of requests per minute to vote,follow,add to favorite (values are being inserted in mysql table) etc

These are only examples real measures are be much higher

Approach 1

There is one executeQueries.php file. executeQueries.php

  <?php
   $action = $_POST['action'];
   switch($action){
      case 'vote':
         #query for inserting vote
      break;
      case 'follow':
         #query for inserting follower
      break;
      case 'favorite':
         #query for inserting favorite
      break;
    }
  ?>

Approach 2

There are three files.

vote.php , follow.php , favorite.php

which contains insert individually to their respective tables


回答1:


For Apache + PHP + a PHP caching scheme, there is no performance difference between the approaches. Whatever PHP file(s) you have will quickly be compiled and cached. Then, running a PHP file will be essentially the same, whether it does everything or just one thing. The IF test in the code is insignificant -- connecting to MySQL and doing the UDPATE will be the biggest time consumers. (I speak from the experience of working for a large Internet company with this configuration for over a decade.)

Ordinary INSERTs/UPDATEs in an ordinary MySQL configuration will stall at about 100 per second because, simply, of spinning disk speeds. There are many ways around that. My point here is that the PHP question is not your most important question.



来源:https://stackoverflow.com/questions/28396183/lots-of-php-files-or-one-big-php-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!