尝试了所有方法,但都无法解决。当客户端浏览器访问各种 PHP 脚本时,错误会在随机时间点出现,在我自己的程序中,当我尝试从 PHP 脚本中提取内容时,有时会引发异常。有时它工作正常,有时则不行。
几年来一切都运行良好,直到几个月前。
有好心人能慢慢指导我完成一系列调试步骤吗?我是 Linux 新手。
htop 截图未显示任何异常现在:
1 [| 0.2%] 5 [ 0.0%]
2 [ 0.0%] 6 [ 0.0%]
3 [ 0.0%] 7 [ 0.0%]
4 [|| 0.5%] 8 [|| 0.7%]
Mem[|||||||||||||||||||||||||5363/32087MB] Tasks: 57, 27 thr; 1 running
Swp[|| 632/16375MB] Load average: 0.04 0.07 0.13
Uptime: 57 days, 22:41:20
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
468 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 0:06.91 /usr/sbin/mysqld
3742 root 20 0 26020 2368 1444 R 0.2 0.0 0:00.09 htop
1235 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 104h /usr/sbin/mysqld
3745 root 20 0 101M 3968 2900 S 0.2 0.0 0:00.03 sshd: [accepted]
851 root 20 0 545M 291M 7936 S 0.0 0.9 1:56.57 php /home/***/fr/fetcher.php
1 root 20 0 34032 2188 1084 S 0.0 0.0 0:47.96 /sbin/init
996 syslog 20 0 250M 22444 820 S 0.0 0.1 2:27.11 rsyslogd
1402 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 4:11.39 /usr/sbin/mysqld
430 root 20 0 20004 492 492 S 0.0 0.0 0:00.13 upstart-udev-bridge --daemon
440 root 20 0 51344 712 712 S 0.0 0.0 0:00.03 /lib/systemd/systemd-udevd --dae
608 root 20 0 15260 368 368 S 0.0 0.0 0:00.08 upstart-socket-bridge --daemon
849 root 20 0 59640 1444 1088 S 0.0 0.0 0:00.00 CRON
850 root 20 0 4444 648 548 S 0.0 0.0 0:00.00 /bin/sh -c php /home/***/fr/fe
856 root 20 0 59640 1044 1040 S 0.0 0.0 0:00.00 CRON
858 root 20 0 4444 460 456 S 0.0 0.0 0:00.00 /bin/sh -c php /home/***/updat
860 root 20 0 341M 5676 3580 S 0.0 0.0 1:43.45 php /home/***/updater/index.ph
931 root 20 0 15276 376 376 S 0.0 0.0 0:00.06 upstart-file-bridge --daemon
965 messagebu 20 0 39216 1000 808 S 0.0 0.0 0:00.47 dbus-daemon --system --fork
997 syslog 20 0 250M 22444 820 S 0.0 0.1 0:00.02 rsyslogd
998 syslog 20 0 250M 22444 820 S 0.0 0.1 2:06.88 rsyslogd
995 syslog 20 0 250M 22444 820 S 0.0 0.1 4:34.06 rsyslogd
1014 root 20 0 43452 1408 1232 S 0.0 0.0 0:00.60 /lib/systemd/systemd-logind
1043 root 20 0 15820 676 672 S 0.0 0.0 0:00.00 /sbin/getty -8 38400 tty4
1045 root 20 0 15820 676 672 S 0.0 0.0 0:00.00 /sbin/getty -8 38400 tty5
1054 root 20 0 15820 676 672 S 0.0 0.0 0:00.00 /sbin/getty -8 38400 tty2
1055 root 20 0 15820 676 672 S 0.0 0.0 0:00.00 /sbin/getty -8 38400 tty3
1058 root 20 0 15820 676 672 S 0.0 0.0 0:00.00 /sbin/getty -8 38400 tty6
1074 root 20 0 4368 388 388 S 0.0 0.0 0:00.02 acpid -c /etc/acpi/events -s /va
1160 root 20 0 23656 724 640 S 0.0 0.0 0:14.16 cron
1161 daemon 20 0 19140 172 172 S 0.0 0.0 0:00.03 atd
1313 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:37.18 /usr/sbin/mysqld
1314 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:35.50 /usr/sbin/mysqld
1315 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:37.36 /usr/sbin/mysqld
1316 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:37.77 /usr/sbin/mysqld
1317 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:37.93 /usr/sbin/mysqld
1318 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:37.12 /usr/sbin/mysqld
1319 mysql 20 0 8626M 4065M 4896 S 0.0 12.7 2:37.22 /usr/sbin/mysqld
F1Help F2Setup F3SearchF4FilterF5Tree F6SortByF7Nice -F8Nice +F9Kill F10Quit
/etc/apache2/apache2.conf 的内容。此目录中还有许多其他 *.conf 文件。
Mutex file:${APACHE_LOCK_DIR} default
#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.
# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
# Include phpmyadmin
Include /etc/phpmyadmin/apache.conf
ServerName localhost
<VirtualHost *:80>
ServerAdmin info@***.com
DocumentRoot "/var/www/html"
ServerName ***.***.com
ServerAlias ***.***.com
ErrorLog "logs/***/error_log"
CustomLog "logs/***/access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info@***.com
DocumentRoot "/var/www/***"
ServerName ***.com
ServerAlias www.***.com
ErrorLog "logs/***/error_log"
CustomLog "logs/***/access_log" common
</VirtualHost>
答案1
这听起来有点像您的服务器偶尔会耗尽资源,因此无法响应。
要查看是否确实如此,一个简单的方法是安装 ( sudo apt-get install htop
) 并运行一个名为 的 Linux 程序htop
。
它会在顶部显示 CPU 和 RAM 的使用量,然后列出打开的进程(程序)。您可以按各列对列表进行排序,以查看哪些进程占用了资源。
顺便说一句,这是一个检查您正在使用的程序类型的好方法,例如,如果您看到任何名为command
或httpd
或/usr/sbin/httpd
类似的东西,您就知道您正在使用 Apache 作为 Web 服务器。
而且因为 htop 是一个只读程序,所以使用它不会破坏任何东西。
答案2
我有充分的理由相信这个问题与我的服务器无关,而是与我用来访问服务器的个人笔记本电脑上的互联网连接有关。我使用沃达丰提供的移动 Wi-Fi 设备(将 4G 转换为 WiFi)连接到互联网。沃达丰服务器不知何故在我的服务器出现任何超时之前就发送了此错误消息。他们对其他服务器也是如此。使用不同互联网连接的其他人在处理我的服务器时不会收到网关超时错误。