Run the ping command in php to test the speed, but the exec () function is useless.

Source: Internet
Author: User

Test procedure:

Exec ("ping baidu.com", $ list );
For ($ I = 0; $ I <count ($ list); $ I ++ ){
Print $ list [$ I]. "\ n ";
}
?>

Chinese materials:
This function is generally only used in linux

Few people put php on a windows server to run it. Some functions in php only support linux. Not all functions can be used on windows!

Exec can be used on win
To run exec in IIS + PHP, you first need to grant the permission to php‑read.exe(users need to add internet Guest user permissions to the security of cmd.exe). Otherwise, an error will occur.
Apache does not know what permissions are used for running, and does not know whether it is a permission issue.

E document:
It's because your host has limited certain functions of PHP.

Exec is a PHP-specific function that your web host disabled with PHP safe mode

It seems that many permissions in windows are not so well solved. Is there any other way to run in xp?
After asking many friends, I finally found the following two functions. Fsockopen and fopen, but both functions have limitations.
If the link is lost, the page will remain stuck and there is no timeout parameter, which is difficult to control.
Fsockopen requires a domain name, but a lot of data in my database is ip addresses, such as http: // 202,234.34 .54, which leads to misjudgment. (I finally used this method)
I found a function on the Internet to extract domain names, but I couldn't find the function, including the www function. Alas, I don't want to be lazy. But I wrote a function get_domain ($ url ){
$ Url1 = $ url;
$ Upos = strpos ($ url1, "http ://");
If ($ upos = 0) $ url1 = str_replace ("http: //", "", $ url1 );
$ Upos = strpos ($ url1 ,"/");

If ($ upos ){
$ Url2 = substr ($ url1, 0, $ upos );
}
Return $ url2;
} // End function

The following is the test code:
Function test ($ testurl ){
$ Fp = @ fsockopen ($ testurl, 80, & $ errno, & $ errstr, 2 );
If (gettype ($ fp )! = Resource ){
$ Remark = "the URL link is invalid! ";
}
}

This function is described in detail on the Internet Many, need to be searched by friends themselves.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.