In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what functions are related to PHP option parameters. The quality of the article is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.
Some PHP options parameter-related functions
For PHP configuration, most of the time we are looking at php.ini file or through the command line to query some information, in fact, PHP some built-in functions can also help us to view or manipulate these configuration parameters. For example, before we learned about php ini file related operation function analysis. The function to modify aspects is only ini_set(), most of the other functions are actually to help us query, today, we will explain these functions one by one.
get_defined_constants()
Returns an associative array of all constants, where keys are constant names and values are constant values.
define("MY_CONSTANT", 1);
print_r(get_defined_constants(true));
// array(
// ……
// [user] => array(
// [MY_CONSTANT] => 1
// )
// )
This function will output all constants, because the return content is a lot, so use...... It means that there are many system or extension defined constants, and the constants we define ourselves in the code will all enter the key name [user].
This function takes one argument, and when it is true, lets the function return a multidimensional array of keys classified in the first dimension, constants and their values in the second dimension. The default is false and returns a one-dimensional array of constant names as keys and their values as keys.
get_extension_funcs()
This function returns the names of all methods included in the extension module.
print_r(get_extension_funcs("swoole"));
// Array
// (
// [0] => swoole_version
// [1] => swoole_cpu_num
// [2] => swoole_last_error
// [3] => swoole_async_dns_lookup_coro
// [4] => swoole_async_set
// [5] => swoole_coroutine_create
// ……
// [35] => swoole_timer_clear
// [36] => swoole_timer_clear_all
// )
Its parameter is the extension name to query, here we directly see the Swoole installed on the machine contains those methods. As you can see, Swoole 4.4 contains 37 method functions.
get_loaded_extensions()
This function returns a list of all loaded extension modules.
print_r(get_loaded_extensions()); // php -m
// Array
// (
// [0] => Core
// [1] => phpdbg_webhelper
// [2] => date
// [3] => libxml
// [4] => openssl
// [5] => pcre
// [6] => sqlite3
// ……
// [65] => imagick
// [66] => swoole
// [67] => vld
// [68] => Zend OPcache
// )
Does this function work the same way we would use-m on the command line to see what extensions are currently installed on the system? Yes, they are the same functionality, and both return a list of such extensions installed. In some open source CMS systems, when you need to check whether the current installation environment meets the requirements, you can use this function to detect.
get_include_path() and get_included_files()
These two functions return configuration information for the current include_path and a list of files that have been included or required.
echo get_include_path(), PHP_EOL; // .:/ usr/local/Cellar/php/7.3.0/share/php/pear
echo ini_get('include_path'), PHP_EOL; // .:/ usr/local/Cellar/php/7.3.0/share/php/pear
get_include_path() is simple, it actually has the same effect as echo ini_get ('include_path'), which reads the configuration value of include_path in php.ini file. When PHP includes or requires, if no path is given, it will look in the current directory first, and if it does not find it, it will look in this include_path. If the specified file is still not found, an error will be reported. This is what the include_path directory does. Of course, we don't use it in our daily development, so we can understand it here.
include "dynamically view and load PHP extensions.php";
print_r(get_included_files());
// Array
// (
// [0]=> /Users/zhangyue/MyDoc/blog post/dev-blog/php/202005/source/some PHP options parameter-related functions (a).php
// [1]=> /Users/zhangyue/MyDoc/Blog/dev-blog/php/202005/source/Dynamic view and load PHP extensions.php
// )
get_included_files() is also a very simple and intuitive function, which returns which files we currently load. The current runtime file is always in the first entry, which means that the function returns at least one of its own file paths. We can try using this function to print the number of loaded files in Laravel or other framework entry files or controllers, which can actually help us understand the loading performance of this framework.
get_resources()var_dump(get_resources());
// array(3) {
// [1]=>
// resource(1) of type (stream)
// [2]=>
// resource(2) of type (stream)
// [3]=>
// resource(3) of type (stream)
// }
$fp = fopen('1.txt','r');
var_dump(get_resources());
// array(4) {
// [1]=>
// resource(1) of type (stream)
// [2]=>
// resource(2) of type (stream)
// [3]=>
// resource(3) of type (stream)
// [5]=>
// resource(5) of type (stream-context)
// }
This function returns information about the active resource. For example, in the above example, we first printed the contents of this function, only 3 pieces of data, and then we loaded a file resource with fopen() to obtain a resource handle. When you print the contents of this function, you will find an extra resource handle of type stream-context. This function can help us check whether there are unreleased resource operations during debugging.
Today, I simply learned a few functions. In fact, they are not very commonly used functions, but after learning, I found that many functions can still help us tune the system or quickly detect the running environment when migrating the system. Learning to use is the most successful learning, let us continue to cheer it!
What are the functions related to PHP options and parameters to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.