In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "PHP view CPU function introduction", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "PHP View CPU Function Introduction"!
1. Any number of arguments to PHP functions
You may know that PHP allows you to define a function with default parameters. But what you may not know is that PHP also allows you to define a function with completely arbitrary parameters
Here is an example of a function that shows you the default parameters:
//function foo($arg1 ='', $arg2 ='') {echo "arg1: $arg1\n";echo "arg2: $arg2\n";}foo ('hello ',' world');/* output:arg1: helloarg2: world*/foo();/* output: arg1:arg2:*/
Now let's take a look at a function with indefinite arguments that uses func_get_args():
//Yes, the parameter list is empty function foo() {//Get array of all passed parameters $args = func_get_args();foreach ($args as $k => $v) {echo "arg". ($k+1). ": $v\n";}}foo();/* Nothing outputs */foo ('hello ');/* outputs arg1: hello*/foo ('hello', 'world',' again');/* outputs arg1: helloarg2: worldarg3: again*/
2. Glob() Find files
There are many PHP functions that have long, self-explanatory function names, but when you see glob(), you probably don't know what the function is for unless you're familiar with it.
Can you believe that this function is good? Scandir(), which can be used to find files.
//Get all files with PHP suffix $files = glob ('*.php');print_r($files);/* Output:Array([0] => phptest.php[1] => pi.php[2] => post_output.php[3] => test.php)*/
You can also find multiple suffixes
//get PHP files and TXT files $files = glob ('*. {php,txt $>', GLOB_BRACE);print_r($files);/* Output:Array([0] => phptest.php[1] => pi.php[2] => post_output.php[3] => test.php[4] => log.txt[5] => test.txt)*/
You can also add the path:
$files = glob('../ images/a*.jpg');print_r($files);/* Output:Array([0] =>../ images/apple.jpg[1] => ../ images/art.jpg)*/
If you want to get an absolute path, you can call? realpath() function:
$files = glob('../ images/a*.jpg');// applies the function to each array element$files = array_map('realpath',$files);print_r($files);/* output looks like:Array([0] => C:\wamp\www\images\apple.jpg[1] => C:\wamp\www\images\art.jpg)*/
3. View memory usage
Observing your program's memory usage allows you to optimize your code better.
PHP has a garbage collection mechanism, and it has a very complex memory management mechanism. You can know how much memory your script uses. To know the current memory usage, you can use? memory_get_usage() function, if you want to know the peak of memory usage, you can call memory_get_peak_usage() function.
echo "Initial: ".memory_get_usage(). " bytes \n";/* Output Initial: 361400 bytes*///Memory used for ($i = 0; $i
< 100000; $i++) {$array []= md5($i);}// 删除一半的内存for ($i = 0; $i < 100000; $i++) {unset($array[$i]);}echo "Final: ".memory_get_usage()." bytes \n";/* printsFinal: 885912 bytes*/echo "Peak: ".memory_get_peak_usage()." bytes \n";/* 输出峰值Peak: 13687072 bytes*/ 4. 查看CPU使用情况 使用?getrusage() 函数可以让你知道CPU的使用情况。注意,这个功能在Windows下不可用。 print_r(getrusage());/* 输出Array([ru_oublock] =>0[ru_inblock] => 0[ru_msgsnd] => 2[ru_msgrcv] => 3[ru_maxrss] => 12692[ru_ixrss] => 764[ru_idrss] => 3864[ru_minflt] => 94[ru_majflt] => 0[ru_nsignals] => 1[ru_nvcsw] => 67[ru_nivcsw] => 4[ru_nswap] => 0[ru_utime.tv_usec] => 0[ru_utime.tv_sec] => 0[ru_stime.tv_usec] => 6269[ru_stime.tv_sec] => 0)*/
This structure looks obscure unless you know a lot about CPU. Here are some explanations:
ru_oublock: block output operation
ru_inblock: block input operation
ru_msgsnd: Message sent
ru_msgrcv: Message received
ru_maxrss: Maximum resident set size
ru_ixrss: Total shared memory size
ru_idrss: all unshared memory sizes
ru_minflt: page recycling
ru_majflt: page failure
ru_nsignals: received signals
ru_nvcsw: Active context switching
ru_nivcsw: passive context switching
ru_nswap: Exchange area
ru_utime.tv_usec: User state time (microseconds)
ru_utime.tv_sec: User state time (seconds)
ru_stime.tv_usec: kernel time (microseconds)
ru_stime.tv_sec: System kernel time? (seconds)
At this point, I believe everyone has a deeper understanding of "PHP View CPU Function Introduction", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.