display_errors设置为Off无效,仍然输出报错

本文介绍了如何解决PHP应用中错误信息泄露的问题,包括修改php.ini、httpd.conf配置及php脚本,针对不同服务器环境(如Apache、IIS、nginx)提供了解决方案,并详细解释了如何排查和修复php-fpm配置中的display_errors参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.xianren.org/web/display_errors-off-no.html


由于使用检测页面异常导致本地路径泄漏,查看360的解决方案:
1、如果是PHP应用程序/Apache服务器,可以通过修改php脚本、配置php.ini以及httpd.conf中的配置项来禁止显示错误信息:
修改php.ini中的配置行: display_errors = off
修改httpd.conf/apache2.conf中的配置行: php_flag display_errors off
修改php脚本,增加代码行: ini_set(‘display_errors’, false);
2、如果是IIS 并且是 支持aspx的环境,可以在网站根目录新建web.config文件(存在该文件则直接修改),或者可以参考这里:http://bbs.webscan.360.cn/forum.php?mod=viewthread&tid=4560&extra=page%3D1
由于使用的是nginx,所以在php.ini的设置:

error_reporting = E_ALL & ~E_NOTICE
display_errors = Off
log_errors = On
error_log = /www/logs/php_error.log

按理说这样,错误信息是不会输出了,但是当PHP有错误时,会把报错提示显示在页面上。
搜索了下,发现有人说当log_errors开启时,如果error_log的路径不对,会导致报错显示。经查与此无关。
输出phpinfo(),查看到display_errors是On。在页面中指定:ini_set(“DISPLAY_ERRORS”,0),仍然无效!
最后发现php-fpm.conf里有句:
引用

Additional php.ini defines, specific to this pool of workers.
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">0</value>
</value>

原来忘了修改这个地方的配置,display_errors被设置为1了!改成0就好了。这里面也说明了在php_defines里可以额外指定某些php的参数。
直接将这两段注释掉,php-fpm reload后,报错提示不再显示到页面上了。


[0]**** Build of configuration Debug for project Lab4 **** [1]"C:\\ti\\ccs2010\\ccs\\utils\\bin\\gmake" -k -j 16 all -O [2]Building file: "../main.c" [3]Invoking: MSP430 Compiler [4]"C:/ti/ccs2010/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/bin/cl430" -vmspx --data_model=restricted --use_hw_mpy=F5 --include_path="C:/ti/ccs2010/ccs/ccs_base/msp430/include" --include_path="C:/Users/14665/workspace_ccstheia/Lab4" --include_path="C:/Users/14665/workspace_ccstheia/Lab4/driverlib/MSP430F5xx_6xx" --include_path="C:/ti/ccs2010/ccs/tools/compiler/ti-cgt-msp430_21.6.1.LTS/include" --advice:power="none" --define=__MSP430F5529__ --define=DEPRECATED -g --printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU23 --silicon_errata=CPU40 --preproc_with_compile --preproc_dependency="main.d_raw" "../main.c" [5]>> Compilation failure [6]subdir_rules.mk:9: recipe for target 'main.obj' failed [7]"../main.c", line 26: error #20: identifier "CSCTL0_H" is undefined [8]"../main.c", line 26: error #20: identifier "CSKEY_H" is undefined [9]"../main.c", line 27: error #20: identifier "CSCTL1" is undefined [10]"../main.c", line 27: error #20: identifier "DCOFSEL_6" is undefined [11]"../main.c", line 28: error #20: identifier "CSCTL2" is undefined [12]"../main.c", line 29: error #20: identifier "CSCTL3" is undefined [13]"../main.c", line 46: error #20: identifier "P4SEL1" is undefined [14]"../main.c", line 47: error #20: identifier "P4SEL0" is undefined [15]"../main.c", line 55: error #20: identifier "UCA1MCTLW" is undefined [16]"../main.c", line 91: warning #1-D: last line of file ends without a newline [17]9 errors detected in the compilation of "../main.c". [18]gmake: *** [main.obj] Error 1 [19]gmake: Target 'all' not remade because of errors. [20]**** Build Finished 报错
06-16
#include <stdio.h> #include <stdlib.h> #pragma pack(push, 1) typedef struct { unsigned short bfType; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; } BITMAPFILEHEADER; typedef struct { unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; } BITMAPINFOHEADER; #pragma pack(pop) // C6000兼容的周期计数函数 unsigned long long get_cycle_count() { unsigned int tsch, tscl; asm(" mvc .s2 TSCH, %0" : "=r"(tsch)); asm(" mvc .s2 TSCL, %0" : "=r"(tscl)); return ((unsigned long long)tsch << 32) | tscl; } int main(void) { const int width = 768, height = 576; const int sizeImage = width * height * 3; const int iterations = 1000; const char *src1_path = "HazyDay1.bmp"; const char *src2_path = "HazyDay2.bmp"; const char *dst_path = "jieguo.bmp"; printf("Starting image processing on C6000 DSP...\n"); printf("Image size: %dx%d, Iterations: %d\n", width, height, iterations); FILE *src1 = fopen(src1_path, "rb"); FILE *src2 = fopen(src2_path, "rb"); FILE *dst = fopen(dst_path, "wb"); if (!src1 || !src2 || !dst) { printf("Error opening files\n"); if (src1) fclose(src1); if (src2) fclose(src2); if (dst) fclose(dst); return -1; } BITMAPFILEHEADER fileHeader; BITMAPINFOHEADER infoHeader; if (fread(&fileHeader, sizeof(BITMAPFILEHEADER), 1, src1) != 1 || fread(&infoHeader, sizeof(BITMAPINFOHEADER), 1, src1) != 1) { printf("Error reading BMP headers\n"); fclose(src1); fclose(src2); fclose(dst); return -1; } unsigned char *img1 = (unsigned char *)malloc(sizeImage); unsigned char *img2 = (unsigned char *)malloc(sizeImage); unsigned char *result = (unsigned char *)malloc(sizeImage); if (!img1 || !img2 || !result) { printf("Memory allocation failed\n"); free(img1); free(img2); free(result); fclose(src1); fclose(src2); fclose(dst); return -1; } fseek(src1, fileHeader.bfOffBits, SEEK_SET); fseek(src2, fileHeader.bfOffBits, SEEK_SET); fread(img1, 1, sizeImage, src1); fread(img2, 1, sizeImage, src2); unsigned long long start_cycles, end_cycles; double total_time_3ch = 0, total_time_1ch = 0; int i, iter; // ================= 三通道同时处理 ================= printf("Running 3-channel method...\n"); start_cycles = get_cycle_count(); for (iter = 0; iter < iterations; iter++) { unsigned char *p1 = img1; unsigned char *p2 = img2; unsigned char *res = result; for (i = 0; i < sizeImage; i++) { *res++ = (*p1++ + *p2++) >> 1; } } end_cycles = get_cycle_count(); total_time_3ch = (double)(end_cycles - start_cycles); // ================= 单通道分别处理 ================= printf("Running 1-channel method...\n"); start_cycles = get_cycle_count(); for (iter = 0; iter < iterations; iter++) { for (i = 0; i < sizeImage; i += 3) { result[i] = (img1[i] + img2[i]) >> 1; result[i+1] = (img1[i+1] + img2[i+1]) >> 1; result[i+2] = (img1[i+2] + img2[i+2]) >> 1; } } end_cycles = get_cycle_count(); total_time_1ch = (double)(end_cycles - start_cycles); // 输出结果 printf("\nProcessing Time Comparison (after %d iterations):\n", iterations); printf("3-Channel Method:\n"); printf(" Total cycles: %.0f\n", total_time_3ch); printf(" Average cycles: %.0f\n", total_time_3ch/iterations); printf("1-Channel Method:\n"); printf(" Total cycles: %.0f\n", total_time_1ch); printf(" Average cycles: %.0f\n", total_time_1ch/iterations); if (total_time_1ch > 0 && total_time_3ch > 0) { double improvement = (total_time_1ch - total_time_3ch) / total_time_1ch * 100; printf("Efficiency Improvement: %.2f%% (%s method is faster)\n", fabs(improvement), improvement > 0 ? "3-channel" : "1-channel"); } // 写入结果 fwrite(&fileHeader, sizeof(BITMAPFILEHEADER), 1, dst); fwrite(&infoHeader, sizeof(BITMAPINFOHEADER), 1, dst); fseek(dst, fileHeader.bfOffBits, SEEK_SET); fwrite(result, 1, sizeImage, dst); // 释放资源 free(img1); free(img2); free(result); fclose(src1); fclose(src2); fclose(dst); return 0; } 为什么有下面的报错 **** Build of configuration Debug for project lab_03_app **** "G:\\ccs\\CCS5.5.0.00077_win32\\ccsv5\\utils\\bin\\gmake" -k all 'Building file: ../main.c' 'Invoking: C6000 Compiler' "G:/ccs/CCS5.5.0.00077_win32/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6740 --abi=coffabi -g --include_path="G:/ccs/CCS5.5.0.00077_win32/ccsv5/tools/compiler/c6000_7.4.4/include" --display_error_number --diag_warning=225 --diag_wrap=off --preproc_with_compile --preproc_dependency="main.pp" "../main.c" "../main.c", line 31: error #18: expected a ")" "../main.c", line 32: error #18: expected a ")" "../main.c", line 33: warning #551-D: variable "tsch" is used before its value is set "../main.c", line 33: warning #551-D: variable "tscl" is used before its value is set 2 errors detected in the compilation of "../main.c". >> Compilation failure gmake: *** [main.obj] Error 1 gmake: Target `all' not remade because of errors. **** Build Finished ****
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值