- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这个问题与我的另一个问题有关,found here .
起初我认为这是一个网络问题,但越来越有可能,这与我的 php 配置和 php 文件的运行有关。我做了以下测试用例:
我创建了一个 php 文件,将其命名为 test.php
,内容如下:
<?php
echo 'test';
?>
并创建了两个 bash 文件,内容如下:
//bash1.sh
#!/bin/bash
/usr/bin/php /testFirstByte/test.php
另一个用
//bash2.sh
#!/bin/bash
echo Test;
然后我开始为它们的运行计时,运行每个运行并在它之前使用“时间”命令,即:time php test.php
结果如下:
// time php test.php
test
real 0m0.548s
user 0m0.445s
sys 0m0.101s
// time sh bash2.hs
Test
real 0m0.002s
user 0m0.002s
sys 0m0.000s
// time sh bash1.hs
X-Powered-By: PHP/5.5.30
Content-type: text/html; charset=utf-8
test
real 0m0.539s
user 0m0.429s
sys 0m0.108s
对我来说,无论何时尝试运行 PHP 脚本,无论我尝试运行哪个 PHP 脚本,运行时间都会增加至少半秒。我不知道如何解决这个问题,所以任何帮助将不胜感激!
编辑 1: 我制作了一个简单的脚本,我希望这就是您所说的内部测试 @Eineki 的意思。脚本如下:
$timer = microtime(true);
require('test_simple.php');
$end = microtime(true) - $timer;
echo "Require test duration was: " . $end . " seconds\n";
$timer = microtime(true);
exec('php test_simple.php');
$end = microtime(true) - $timer;
echo "Exec test duration was: " . $end . " seconds\n";
结果如下:
Require test duration was: 0.00102400779724 seconds
Exec test duration was: 0.61318397522 seconds
编辑 2: 加载的扩展列表如下:
Array
(
[0] => Core
[1] => date
[2] => ereg
[3] => libxml
[4] => openssl
[5] => pcre
[6] => sqlite3
[7] => zlib
[8] => bcmath
[9] => bz2
[10] => calendar
[11] => ctype
[12] => curl
[13] => dom
[14] => hash
[15] => fileinfo
[16] => filter
[17] => ftp
[18] => gd
[19] => gettext
[20] => SPL
[21] => iconv
[22] => session
[23] => json
[24] => mbstring
[25] => mcrypt
[26] => standard
[27] => mysql
[28] => mysqli
[29] => mysqlnd
[30] => Phar
[31] => posix
[32] => Reflection
[33] => imap
[34] => SimpleXML
[35] => sockets
[36] => exif
[37] => tokenizer
[38] => xml
[39] => xmlreader
[40] => xmlwriter
[41] => zip
[42] => cgi-fcgi
[43] => PDO
[44] => pdo_sqlite
[45] => pdo_mysql
[46] => mailparse
[47] => Zend OPcache
)
这是我的 php 版本,截至 php -v
:
PHP 5.5.30 (cgi-fcgi) (built: Dec 3 2015 06:55:27)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
编辑 3: 按照 @voter 的建议在生产服务器(有问题的服务器)和我们的开发服务器上的 php 文件上运行 strace
,不会出现此问题的地方。 strace
输出的所有内容在生产服务器上基本上是开发服务器上的 10 倍。也许熟悉 strace
的人可以由此得出结论?
编辑 4:
vmstat 1
命令摘录:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
5 0 3163644 5410932 2522564 13417292 0 1 22 62 1 0 18 6 75 1 0
2 0 3163644 5845884 2522568 13406468 0 0 0 916 31787 5966 9 6 85 0 0
8 0 3163644 5439468 2522572 13406840 0 0 8 432 50513 5322 12 6 82 0 0
4 0 3163644 5750124 2522572 13407624 0 0 4 232 54417 5615 8 7 86 0 0
4 0 3163644 5748608 2522576 13407480 0 0 4 760 118206 5736 7 9 83 0 0
3 0 3163644 5742648 2522576 13418040 0 0 0 244 68462 6689 10 7 83 0 0
4 0 3163644 5671104 2522576 13407620 0 0 40 568 34157 4222 7 5 87 0 0
4 0 3163644 5980828 2522580 13401712 0 0 16 524 43754 6391 17 6 77 0 0
5 0 3163644 5506988 2522592 13418868 0 0 264 280 59452 5955 16 7 77 0 0
5 0 3163644 5577116 2522600 13417800 0 0 32 540 68056 8968 11 6 83 0 0
7 0 3163644 4747580 2522612 13451468 0 0 16 376 241800 7107 12 13 75 0 0
4 0 3163644 4948548 2522616 13440832 0 0 12 468 354599 5155 7 16 77 0 0
编辑 5:
top
命令在服务器上的结果:
top - 09:17:58 up 15 days, 1:53, 8 users, load average: 6.90, 6.22, 5.34
Tasks: 687 total, 3 running, 683 sleeping, 0 stopped, 1 zombie
Cpu(s): 15.0%us, 3.4%sy, 0.0%ni, 80.7%id, 0.8%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 49390000k total, 43364688k used, 6025312k free, 2697344k buffers
Swap: 16482300k total, 3495772k used, 12986528k free, 11878096k cached
最佳答案
您的 php -v
输出看起来像是您从命令行调用 php cgi。
对于命令行,通常有 php 的 CLI 版本,可以单独安装,例如apt-get install php5-cli
.
这会对性能产生相当大的影响。在中型 Linux 服务器上的快速测试给了我
#time php-cgi test.php
X-Powered-By: PHP/5.5.26
Content-type: text/html
test
real 0m0.117s
user 0m0.036s
sys 0m0.076s
# time php test.php
test
real 0m0.074s
user 0m0.040s
sys 0m0.036s
可以看到,cgi版本的时间翻倍了。您能否尝试使用 CLI 版本来查看差异是否仍然那么大?
这可能不会帮助您解决您提到的另一个线程中的问题,除非您也在那里使用 CGI 模块并且没有正确配置它。
关于php - 在服务器上执行 php 脚本非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48945666/
我在 JavaScript 文件中运行 PHP,例如...... var = '';). 我需要使用 JavaScript 来扫描字符串中的 PHP 定界符(打开和关闭 PHP 的 )。 我已经知道使
我希望能够做这样的事情: php --determine-oldest-supported-php-version test.php 并得到这个输出: 7.2 也就是说,php 二进制检查 test.
我正在开发一个目前不使用任何框架的大型 php 站点。我的大问题是,随着时间的推移慢慢尝试将框架融入应用程序是否可取,例如在创建的新部件和更新的旧部件中? 比如所有的页面都是直接通过url服务的,有几
下面是我的源代码,我想在同一页面顶部的另一个 php 脚本中使用位于底部 php 脚本的变量 $r1。我需要一个简单的解决方案来解决这个问题。我想在代码中存在的更新查询中使用该变量。 $name)
我正在制作一个网站,根据不同的情况进行大量 PHP 重定向。就像这样...... header("Location: somesite.com/redirectedpage.php"); 为了安全起见
我有一个旧网站,我的 php 标签从 因为短标签已经显示出安全问题,并且在未来的版本中将不被支持。 关于php - 如何避免在 php 文件中写入
我有一个用 PHP 编写的配置文件,如下所示, 所以我想用PHP开发一个接口(interface),它可以编辑文件值,如$WEBPATH , $ACCOUNTPATH和 const值(value)观
我试图制作一个登录页面来学习基本的PHP,首先我希望我的独立PHP文件存储HTML文件的输入(带有表单),但是当我按下按钮时(触发POST到PHP脚本) )我一直收到令人不愉快的错误。 我已经搜索了S
我正在寻找一种让 PHP 以一种形式打印任意数组的方法,我可以将该数组作为赋值包含在我的(测试)代码中。 print_r 产生例如: Array ( [0] => qsr-part:1285 [1]
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: What is the max key size for an array in PHP? 正如标题所说,我想知道
我正在寻找一种让 PHP 以一种形式打印任意数组的方法,我可以将该数组作为赋值包含在我的(测试)代码中。 print_r 产生例如: Array ( [0] => qsr-part:1285 [1]
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我在 MySQL 数据库中有一个表,其中存储餐厅在每个工作日和时段提供的菜单。 表结构如下: i_type i_name i_cost i_day i_start i_
我有两页。 test1.php 和 test2.php。 我想做的就是在 test1.php 上点击提交,并将 test2.php 显示在 div 中。这实际上工作正常,但我需要向 test2.php
我得到了这个代码。我想通过textarea更新mysql。我在textarea中回显我的MySQL,但我不知道如何更新它,我应该把所有东西都放进去吗,因为_GET模式没有给我任何东西,我也尝试_GET
首先,我是 php 的新手,所以我仍在努力学习。我在 Wordpress 上创建了一个表单,我想将值插入一个表(data_test 表,我已经管理了),然后从 data_test 表中获取所有列(id
我有以下函数可以清理用户或网址的输入: function SanitizeString($var) { $var=stripslashes($var); $va
我有一个 html 页面,它使用 php 文件查询数据库,然后让用户登录,否则拒绝访问。我遇到的问题是它只是重定向到 php 文件的 url,并且从不对发生的事情提供反馈。这是我第一次使用 html、
我有一个页面充满了指向 pdf 的链接,我想跟踪哪些链接被单击。我以为我可以做如下的事情,但遇到了问题: query($sql); if($result){
我正在使用 从外部文本文件加载 HTML/PHP 代码 $f = fopen($filename, "r"); while ($line = fgets($f, 4096)) { print $l
我是一名优秀的程序员,十分优秀!