大量的 php 文件或一个大的 php 文件 [英] Lots of php files or one big php file

查看:47
本文介绍了大量的 php 文件或一个大的 php 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当网站有数百万用户每天发出数百万次请求时,我想知道哪种方法在速度和性能方面更好.

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.

怎么了?- 每分钟数以千计的投票请求、关注请求、添加到收藏夹(值被插入到 mysql 表中)等

这些只是示例,实际测量值要高得多

有一个 executeQueries.php 文件.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;
    }
  ?>

方法 2

共有三个文件.

Approach 2

There are three files.

vote.phpfollow.phpfavorite.php

其中包含单独插入各自的表

which contains insert individually to their respective tables

推荐答案

对于 Apache + PHP + PHP 缓存方案,这两种方法之间没有性能差异.无论您拥有什么 PHP 文件,都将很快被编译和缓存.然后,运行一个 PHP 文件基本上是一样的,无论它做所有事情还是只做一件事.代码中的 IF 测试无关紧要——连接到 MySQL 并执行 UDPATE 将是最大的时间消耗者.(我是根据在一家采用这种配置的大型互联网公司工作了十多年的经验说的.)

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.)

普通 MySQL 配置中的普通 INSERTs/UPDATEs 会以每秒 100 次左右的速度停滞,原因很简单,因为磁盘速度旋转.有很多方法可以解决这个问题.我的观点是 PHP 问题不是您最重要的问题.

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.

这篇关于大量的 php 文件或一个大的 php 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆