This article mainly introduces the five methods of requesting URLs in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.
Five methods:
The first three are the basic file operation functions of PHP
curl()
is a PHP extension that needs to be enabled and installed under Linux.
exec()
is executed The command wget under the linux command line downloads remote files
. The wget command failed when testing the local virtual machine to request http://www.baidu.com, but failed on the remote server. Yes, considering the problem of DNS resolution, I directly requested the IP and successfully downloaded the index.html file.
Only methods are provided here. The advantages and disadvantages require a detailed understanding of the functions and defects of each method.
1. fopen() function
1 2 3 4 5 6 7 8 9 10 |
|
2 , file() function
1 2 |
|
##3. file_get_contents() function
1 |
|
##4. Curl() requests remote url data
1 2 3 4 5 6 7 8 |
|
5. exec() executes the command line command##
1 2 |
|
Related recommendations:
php implements c
url upload, download, https login
U method in thinkphp is generated according to routing rules
Detailed explanation of stepsPHP transfer session c
urlThe above is the detailed content of Five ways to request url in php. For more information, please follow other related articles on the PHP Chinese website!