아파치에 가상 호스트가 있습니다. 우분투 10.04 램프를 사용하고 있습니다.브라우저 요청 당 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);
?>
: 코드를 가지고,
127.0.0.1 site_folder.com
내가 one.php라는 이름의 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>
나는/라인을 호스트/등의 추가
브라우저에서 스크립트 (http://localhost/one.php 또는 site_folder.com/one.php)를 실행하면 logs.txt에서 같은 메시지가 세 번 기록됩니다 :
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가 폴더 내에 없습니다. .
1)$_SERVER['REQUEST_URI'] => /one.php?XDEBUG_SESSION_START=netbeans-xdebug
2)$_SERVER['REQUEST_URI'] => /one.php
3)$_SERVER['REQUEST_URI'] => /one.php
내가 한 번만 내 메시지를 기록해야합니다
는 내가 발견 한 것은 $ _SERVER [ 'REQUEST_URI는'] 약간의 각 실행/반복을 변경한다는 것입니다. 난 당신이, 실제 서버에서 작업을 수행하는 대신 로컬 호스트를 시도했다 ... 당신이 그것을 밖으로 시도한다고 가정하지만,
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/
하나의 test.php 파일을 종속성없이 설정하고이를 호출 해보십시오. 파일 로거가 연결되어 있는지 확인하십시오. – JohnP
one.php는 아무런 의존성이 없다. 주어진 코드 만 포함하고 실행될 때마다 메시지를 기록한다. – Nikos