每个浏览器请求多次执行 php 脚本

标签 php apache debugging virtualhost

我在 apache 中有一个虚拟主机。我在 ubuntu 10.04 上使用 LAMP。

<VirtualHost *:80>
DocumentRoot /home/username/websites/site_folder
ServerName www.site_folder.com
ServerAlias site_folder.com
    <Directory /home/username/websites/site_folder/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

我在/etc/hosts 中添加了这一行:

127.0.0.1 site_folder.com

在虚拟主机的文件夹中,我添加了一个名为 one.php 的 php 脚本,代码如下:

<?php
$today = getdate();
$handle = fopen("logs/logs.txt", "a");
fwrite($handle, $today['mday'].'/'.$today['mon'].'/'.$today['year']." this is a log post"." \n");
fclose($handle);
?>

当我从浏览器运行脚本时,http://localhost/one.php或 site_folder.com/one.php,logs.txt 已记录相同的消息 3 次:

12/4/2011 this is a log post 
12/4/2011 this is a log post 
12/4/2011 this is a log post 

使用 netbeans 调试器,我看到脚本实际上重复了 3 次(到达脚本末尾后,它从同一脚本的开头继续 ->one.php) 文件夹中不存在 .htaccess。

我注意到 $_SERVER['REQUEST_URI'] 每次执行/重复都会发生一些变化:

1)$_SERVER['REQUEST_URI'] => /one.php?XDEBUG_SESSION_START=netbeans-xdebug
2)$_SERVER['REQUEST_URI'] => /one.php
3)$_SERVER['REQUEST_URI'] => /one.php

我只需要记录一次消息。

我从 apache2.conf 添加了未注释的指令:

ServerRoot "/etc/apache2"
LockFile /var/lock/apache2/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_event_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>
DefaultType text/plain
HostnameLookups Off
ErrorLog /var/log/apache2/error.log
LogLevel warn
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/httpd.conf
Include /etc/apache2/ports.conf
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
CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined
Include /etc/apache2/conf.d/
Include /etc/apache2/sites-enabled/

最佳答案

我想您已经尝试过了,但是...,您是否尝试过从真实的服务器而不是本地主机上进行操作?我的意思是,问题可能出在你的 Apache 服务器上......

我不知道,只是把它当作一个简单的想法来测试。

关于每个浏览器请求多次执行 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5637860/

相关文章:

PHP MySQL 搜索引擎多输入

java - 在 Mac 上用 Eclipse 运行 tomcat

java - ACRA 似乎正在报告处理异常导致的崩溃

c - 在 HP-UX 上使用 libunwind 并获取堆栈跟踪

php - Apache 不更新环境变量

debugging - 有没有办法知道谁拥有对 Go 中对象的引用?

php - 在mysql字段中插入≠(不等于)

javascript - 如何从表单发送数据并将它们添加到现有的 POST 数据中,并在 PHP 中将它们连接到一个文本?

php - 帮助使用 PHP mail() 函数

PHP、Linux、 Apache : naming file based on user input