PHP.INI Configuration File Tour 2_PHP Tutorial
The first part of the article has led you through the structure of the php.ini file and explained how to modify the PHP search path, error handling, and parser related options. The second part will delve into the configuration file, including how to activate PHP extension options, set resource limits for PHP scripts, and dynamically change configuration variables through PHP scripts. Activating extension options There are many different extension options available for PHP. On UNIX systems, extension options need to be created at compile time; for Windows, the binary DLL file will include itself with the PHP distribution. The variable extension_dir contains the name of the directory where PHP should look for relevant extension options. extension_dir = "C:Program FilesInternet ToolsApache inphp4extensions" PHP under Windows includes 20 different extension options, and they are all listed in the php.ini file (via comments). To activate a specific extension option just remove the semicolon from the beginning of the corresponding line and restart the server. If you want to disable an extended option (for example, if you need to improve system performance), just add the semicolon again at the beginning of the line. If the extension options are not listed in the php.ini file, you can use the variable extension and pass the corresponding DLL file name to this variable. extension=php_domxml.dll extension=php_dbase.dll Set extension-specific variables The extension-specific variables are stored in a separate area in the configuration file. For example, all variables related to MySQL extensions should be stored in the [MySQL] area of php.ini. If you need to use PHP's mail() function, you need to set the following three variables. When sending email messages through the PHP mail() function, you need to use SMTP and the variable sendmail_from (Windows systems) or the variable sendmail_path (UNIX systems). For Windows, these variables set the SMTP server used and the "From:" address displayed in the email message; while for UNIX, the variable sendmail_path sets the path of the MTA (mail transfer agent) for mail transfer. . SMTP = myserver.localnet.com sendmail_from = me@localhost.com sendmail_path = /usr/sbin/sendmail The variables java.class.path, java.home, java.library and java.library.path are all used to set the search for Java classes and The path to the library. These values will be used by Java extensions, so if you want PHP to integrate correctly with Java programs, you must ensure that these variables are set correctly. java.class.path = .php_java.jar java.home = c:jdk java.library = c:jdkjre inhotspotjvm.dll java.library.path= . The variable session.save_path specifies the temporary directory required to save session information. Normally, this directory defaults to /tmp, but since this default directory does not exist on Windows systems, you must reset it to the correct Windows temporary directory, otherwise the session handler will call the session_start() function Annoying error messages pop up. At the same time, the validity period of the session cookie can be controlled through the variable session.cookie_lifetime. session.save_path = c:windows emp session.cookie_lifetime = 1800 Security settings In php.ini, there are many variables related to security issues of PHP installation. The most interesting one is the safe_mode variable, which is recommended to be set for ISPs and shared-hosting services. This variable will limit the user's use of PHP. safe_mode = Off When safe mode is turned on, you can specify the directory to search for related files through the variable safe_mode_include_dir. By placing the binary program in a specific directory and telling PHP the directory using the safe_mode_include_dir variable, PHP will limit the kinds of programs that can use the exec() command to run PHP scripts. Only binary files in this directory can be accessed through the exec() command. safe_mode_include_dir = /usr/local/lib/php/safe-include safe_mode_exec_dir = /usr/local/lib/php/safe-bin You can also limit file operations through the variable open_basedir. This variable will set the directory name as the root for file operations. After this variable is set, files stored outside this directory tree will not be accessible to PHP. This is a great way to restrict users to their home or web directories on a shared system. open_basedir = /home/web/ The variable max_execution_time sets the time that PHP waits for the script to complete before forcibly terminating the script. This time is calculated in seconds. This variable is useful when the script enters an infinite loop. However, this feature can also cause the operation to fail when there is a legitimate activity that takes a long time to complete (such as uploading a large file). In such cases, you must consider increasing the value of this variable to prevent PHP from shutting down the script while it is executing some important process. max_execution_time = 90 We just mentioned uploading, now let’s take a look at how to configure the uploads variable and form variable. Configuring file uploads and form variables If the security strength provided by the security configuration we discussed earlier in the article does not meet your requirements, you can further improve the security strength by turning off file uploads or setting a maximum file size limit for each upload. The above two functions will be implemented through the variables file_uploads and upload_max_filesize respectively.Generally speaking, unless your system has an application designed to receive files (such as a photo album based on a Web FTP service), you should set a relatively small file size limit. file_uploads = On upload_max_filesize = 2M If you don't care about uploading files, but use a lot of forms in your PHP application, here are two variables that will be of great interest to you. The first is the variable register_globals, which solves a long-standing pain point for PHP developers. In PHP 3.x, this variable defaults to On. This way the form variables will be automatically converted into PHP variables when the form is submitted. In PHP 4.x, this variable is set to Off by default for security reasons. As a result, form variables will only be accessed through specific $_GET and $_POST. This also caused many scripts written in PHP 3.x to have runtime problems, requiring developers to rewrite the scripts and retest them. For example, the value entered into the form field will be understood as $email for a PHP 3.x script; but will be interpreted as $_POST[email] or $_GET[email] for a PHP 4.x script. Normally, this variable can be set to Off, which can provide more secure protection against script attacks through forms. If compatibility with earlier PHP 3.x scripts needs to be considered, it should be set to On. register_globals = Off A variable related to form submission is post_max_size, which will control the maximum amount of data that PHP can receive in a form submission using the POST method. It seems unlikely that the default 8 MB will need to be changed to a larger size. Instead, it should be appropriately reduced to a more realistic value. But if you want to use the PHP file upload function, you need to change this value to be larger than upload_max_filesize. post_max_size = 8M The max_input_time variable was added in PHP 5. This variable can limit the time in seconds for receiving data through POST, GET and PUT methods. If your application is running on a slow link, you may need to increase this value to accommodate the additional time required to receive data. max_input_time = 90 Performance Tuning You can also improve the performance of the PHP parser by adjusting some variable values. To avoid running scripts from using up a lot of available system memory, PHP allows you to define memory usage limits. Use the memory_limit variable to specify the maximum memory capacity that a single script can use: memory_limit = 8M The value of the variable memory_limit should be appropriately larger than the value of post_max_size. Another method that can be used to improve performance is to disable the variables $argc and $argv, which are used to store the number of arguments passed to the application on the command line and the actual argument values. register_argc_argv = false Similarly, you can also disable $HTTP_GET_VARS and $HTTP_POST_VARS, because you are unlikely to use the first two methods today when $_GET and $_POST are used. Disabling this feature can bring performance improvements, but this is only possible through the variable register_long_arrays in PHP 5. register_long_arrays = false function ini_set() Finally, you need to pay attention to the ini_set() function. When PHP reads all the setting information in the php.ini configuration file, it also provides the function of using the ini_set() function to change these settings according to the per-script principle. This function receives two parameters: the name of the configuration variable that needs to be adjusted, and the new value of the variable. For example, to increase the maximum execution time when a script appears: Such a setting will only affect the script being set. Once the script has finished executing, the variable will automatically be restored to its original value. If the PHP application is running on a shared server, you are unlikely to have access to the main php.ini configuration file. At this time, the function ini_set() can allow dynamic modification of the PHP configuration according to special requirements, which will bring you great convenience.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment