search
HomeBackend DevelopmentPHP TutorialPHP.INI配置文件漫游_PHP

PHP.INI配置文件漫游_PHP

Jun 01, 2016 pm 12:25 PM
phpvariabledocumentroamingset upConfiguration

   PHP配置文件

  在开始浏览PHP配置文件之前,值得注意的是PHP配置文件的内部结构化。这个文件叫php.ini,它和许多Windows应用程序中广泛使用的INI文件具有相同的结构。php.ini是一个ASCLL文本文件,其分为多个部分,每一部分包括相关的参数,如下所示:

  [MySection]
variable="value"
anothervariable="anothervalue

  每一部分的名称位于最前面的方括号内,接着是名称对数字,每一名称对占单独一行。因为用规则PHP代码,参数名称非常敏感,不能包含有空格.但是参数值可以是数字,字符串或者布尔逻辑数。

  分号位于每一行的开始,其作为指定标记。这就使它很容易使用或者不使用PHP的这些特性;而无需通过删除该行而实现.你可以对其进行注解,由此该行不会编译。如果你想在以后数据库中再次使用这一特性,这是非常方便,你不需要将其从文件中删除。

  为了获得PHP的识别,php.ini文件必须放置在当前目录下,而这一目录是在$PHPRC环境参数中定义,或者是在编译时间内指定的目录(对于Windows PHP,就是首要Windows目录)。

  通过php.ini文件对PHP格式做出改变之后,你将需要重新启动Web服务器,以便你的改变生效(当然,这是假定你正在通过Web服务器使用PHP的情况)。对于使用PHP的命令行情况,每调入一个PHP二进制程序,配置文件就会被读入一次。

  设置解析器选项

  在这一过程中,第一步是最为重要的一步,即与语言解释程序相关的选项。这里首要选项为引擎参数,其控制PHP服务器为“On”或者为“Off”。关闭服务器表示嵌入的PHP代码不会被Web服务器解析。然而通常将服务器保持“On”状态。

  engine = On

  short_open_tag参数控制语法分析器是否识别快捷键...?>,类似于识别标准键。如果这一参数与其它语言发生冲突,或者如果你想在PHP代码中使用严格语法规则,就关闭该参数。

  short_open_tag = On

  通常情况下,在任何由程序产生输出之前,Cookie或者HTTP数据必须被发送。如果在程序中无法实现这些,你可以通过使用输出缓冲器(output_buffering)参数,使PHP调用输出缓冲器生效。

  通过输出缓冲器为“On”状态,PHP将程序输出存储在一个专门的记忆缓冲器,且在明确指定发送的时间段发送。这就允许你在编写程序过程或者是快要结束的时候,发送特殊的HIIP标题和重要数据,但是,它也会下降一些重要的功能。

  output_buffering = Off

  

  你也可以通过output_buffering参数值指明缓冲器大小,例如:

  output_buffering = 2048

  

  当PHP启动时,它添加一条有关版本号的信息到Web服务器的标准标题框。为了关闭这一特性,可以设定expose_php为false。这是非常有用,例如,你可以防止黑客而把你的网页服务器容量隐藏起来。

  expose_php = On

  

  现在让我们来看看怎样设置搜索路径和捕捉错误。

  设置PHP搜索路径

  你可以使用include_path参数设置PHP的搜索路径,这一参数可以接收系列的目录。当PHP遇到没有路径的文件提示时,它将会自动检测这些目录。

  如果你频繁使用函数库或者类时,可以列出它们当前位置以简化文件的查找。这也是增加路径到PHP的PEAR目录的一个好方法,PEAR目录中包含许多可以重复使用的类。

  include_path = ".:/usr/local/lib/php/pear:"

  

  Window用户可以通过分号指定多个位置,而UNIX用户必须用冒号隔开。

  对于这一小节内容,最好的两个参数是auto_prepend_file和auto_append_file。这些参数指定了一些文件,而这些文件在PHP启动和结束时自动设置数据文件的搜索路径。这一特性大多数用于设置PHP运行中页面的标题和页角的搜索路径,这就使得你可以在编写的每个PHP文件中省去几行代码。但是不足的是,指定的文件将会被添加*all* PHP文档,因此,这些参数最适合于单一程序的服务器。

  这些文件既可以是PHP程序,也可以是HTML文件。嵌入的PHP代码必须用标准的

  auto_prepend_file = /home/web/includes/header.php
auto_append_file = /home/web/includes/legal.php

  

  捕捉错误

  PHP错误分成四类:分析错误,代码错误通知(比如没有初始化的参数),警告(不是很严重的错误),以及严重错误。一般来说,PHP遇到分析错误,或者一般错误,或者是一个非常致命的错误,它就显示错误。如果错误非常严重,它就有可能停止程序处理。你可以用error_reporting参数改变这一特性,此参数可以识别一些错误代码,而且可以显示对应错误的程序代码。

  error_reporting = E_ALL

  

  为了关闭错误的显示,可以设置display_errors参数为false。相反,设置log_errors参数可以将错误信息写入错误日志。

  从安全角度出发,关闭错误显示是有好处的。隐藏系统的详细信息,别有用意的用户就不能打开和毁坏你的网页或者程序。你应该把这些错误通过设置error_log参数指定一个文件名,写在一个自定义日志文件中,或者通过指定特定参数“syslog”,把错误写入系统记录中。请记住,你应该有规律性的检查这些日志文件,以查看日志文件发生的变化。

  display_errors = Off
log_errors = On
error_log = "error.log"

  

  在这篇文章的第二部分,我将会更进一步谈到php.ini文件,讨论诸如以下的设置,包括:文件上传,表格解析,以受限模式运行PHP以获得更好的安全性,激发可扩展功能,设置资源的内存使用,以及使一些特性无效化以提高性能。

  文章第一部分已经带领你领略了php.ini文件的结构,并且说明了如何修改PHP查找路径、差错处理,以及解析器的相关选项。第二部分将深入配置文件,内容包括如何激活PHP扩展选项、针对PHP脚本设置资源限制,以及通过PHP脚本动态改变配置变量。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.