2011-04-12 72 views
3

我在apache中有一個虛擬主機。我在使用LAMP的Ubuntu 10.04上。每個瀏覽器請求多次執行php腳本

<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 /承載線:

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/ 
+0

設置一個沒有依賴關係的test.php文件,然後嘗試調用它。確保你有一個文件記錄器連接。 – JohnP 2011-04-12 15:49:03

+0

one.php沒有依賴關係,它只包含給定的代碼,並且每次執行都會記錄一條消息 – Nikos 2011-04-12 16:17:04

回答

0

我已經重新安裝了服務器,現在一切正常。

0

我想你嘗試過了,但是......,你試圖從一個真正的服務器做,而不是本地主機呢?我的意思是,麻煩可能是在你的Apache服務器...

我不知道,只是把它看作一個簡單的想法來測試。

+0

我非常肯定這種行爲是因爲我的本地配置(除了apache中的虛擬主機,我沒有做任何調整,我安裝了tasksel/LAMP),但我想知道爲什麼 – Nikos 2011-04-12 16:24:29

+0

你可以發佈你的httpd.conf文件嗎?也許我們可以看到原因,那是你在Apache中的主要配置文件。 – elvenbyte 2011-04-13 07:26:32