开发者

php fsockopen curl file_get_contents

I am new to these thing. what are the difference between fsockopen, curl,and file_get_contents. Can someone explain in simple way. I went through the 开发者_C百科manual, but i could not sortout the difference between them.


A long time ago, if you wanted an easy time, you had to use curl extension.

If your host did not provide it, then you were stuck using fsockopen, which is more tedious and finicky, though very versatile.

In more recent versions of PHP, they gave you file_get_contents(), which can save a lot of lines of fopen/fsockopen code for doing something simple like getting the content of a file.

Now, whenever you want to do a simple read of a file, use file_get_contents(). If it is a remote file, you can still get it if your allow_url_fopen in php.ini is set to true.

If allow_url_fopen is not true and you can't change it and you need a remote file, then use curl. Curl can also put things in remote files. file_put_contents() can also put things in files and save some lines of code.

Use fsockopen when you need to do fancy arbitrary things over a network connection, like wait for a response, send more data, count bytes, connect to weird ports, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜