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

时间:2011-04-12 15:37:13

标签: php apache debugging virtualhost

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

<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

在vhost的文件夹中,我添加了一个名为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次(在到达脚本结束后,它从同一个脚本的开头继续 - &gt; 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/

2 个答案:

答案 0 :(得分:0)

我想你试过了,但是......,你试过从真正的服务器,而不是本地服务器吗?我的意思是,问题可能出在Apache服务器......

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

答案 1 :(得分:0)

我重新安装了服务器,现在一切正常。