错误信息提示:
错误号:12142

错误原因:

错误SQL语句:
select * from user_skin where  find_in_set('sysai.net',replace(host,'|',','))

Warning: fopen(/error/2025-06-27.txt): failed to open stream: No such file or directory in /opt/lampp/htdocs/sysai/inc/datai.php on line 247
文件 2025-06-27.txt 不可写

sysai
『 자료실 』
현재위치 : HOME > 자료실
php文件包含目录配置open_basedir的使用与性能分析
글쓴이 : 매니저 작성일 : 2020-03-03
1.open_basedir介绍
open_basedir 将php所能打开的文件限制在指定的目录树中,包括文件本身。当程序要使用例如fopen()或file_get_contents()打开一个文件时,这个文件的位置将会被检查。当文件在指定的目录树之外,程序将拒绝打开。
本指令不受安全模式打开或关闭的影响。 

2.open_basedir设置方法
1.在php.ini 加入
open_basedir="指定目录"
1
2.在程序中使用
ini_set('open_basedir', '指定目录');
1
但不建议使用这种方法
3.在apache的httpd.conf中的Directory配置
php_admin_value open_basedir "指定目录"
1
httpd.conf中的VritualHost
php_admin_value open_basedir "指定目录"
1
4.nginx fastcgi.conf
fastcgi_param PHP_VALUE "open_basedir=指定目录"
1
用open_basedir指定的限制实际上是前缀,不是目录名。 
也就是说 open_basedir=/home/fdipzone 也会允许访问/home/fdipzone_abc,如果要将访问限制为目录,请使用斜线结束路径名,例如:open_basedir=”/home/fdipzone/”
如果要设置多个目录,window使用;分隔目录,linux使用:分隔目录。 

3.使用open_basedir限制目录访问
首先创建一个VirtualHost, 
设置open_basedir 为/home/fdipzone/sites/in.fdipzone.com/

    ServerAdmin webmaster@localhost
    DocumentRoot /home/fdipzone/sites/in.fdipzone.com
    ServerName in.fdipzone.com
    php_admin_value open_basedir "/home/fdipzone/sites/in.fdipzone.com/"
   
        allow from all Options + Indexes
   


1
2
3
4
5
6
7
8
9
在上一层目录 /home/fdipzone/sites/ 中创建一个test.txt文件,在in.fdipzone.com中创建php执行以下代码
echo file_get_contents('../test.txt');
?>
1
2
3
因为test.txt不在限定的目录范围内,因此php提示警告 
Warning: file_get_contents(): open_basedir restriction in effect. File(../test.txt) is not within the allowed path(s): (/home/fdipzone/sites/in.fdipzone.com/) in /home/fdipzone/sites/in.fdipzone.com/index.php on line 3 

4.设置open_basedir的性能分析
open_basedir开启后会影响I/O,因为每个调用的文件都需要判断是否在限制目录内。
测试程序,读取限制目录内同一文件10000次
// 记录开始时间
$starttime = getMicrotime();
// 读取10000次文件
for($i=0; $i<10000; $i++){
    file_get_contents('test.txt');
}
// 记录结束时间
$endtime = getMicrotime();
printf("run time %f ms\r\n", ((float)($endtime)-(float)($starttime))*1000);
function getMicrotime(){
    list($usec, $sec) = explode(' ', microtime());
    return (float)$usec + (float)$sec;
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
关闭open_basedir测试 
run time 137.237072 ms
打开open_basedir测试 
run time 404.207945 ms
开启open_basedir后,执行时间是关闭的3倍。
 
总结:使用open_basedir可以限制程序可操作的目录和文件,提高系统安全性。但会影响I/O性能导致系统执行变慢,因此需要根据具体需求,在安全与性能上做平衡。
————————————————
版权声明:本文为CSDN博主「傲雪星枫」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/fdipzone/article/details/54562656
목록


홈으로 | 이용안내 | 이용약관 | 개인정보보호정책 | 제휴문의 | 질문과답변 | 자주하는 질문
Copyright © 2011 - 2014 SYSAI Work Group, All Rights Reserved 주소:길림성연길시,우편:133300 Version 3.0 Run Time 0.257s