开发者

which of this functions are faster and better? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

for remote a file from a server to another server which of this functions is bett开发者_如何学编程er and faster ?

FSOCKOPEN | Copy | FOPEN | FILE_GET_CONTENTS | cURL

Thanks is advanced


If you're using these functions to transfer data from/to other hosts, the local speed doesn't matter, it will be dwarfed by the time it takes to transfer the data.

Use each function for what it's good for. In php, you can choose between using stream wrappers with most file functions or specialized functions.

Generic file functions that can be used with protocol wrappers:

  • copy - Well, copy a file.
  • rename - Move/rename a file.
  • file_get_contents - Read a file.
  • file_put_contents - Write a file.
  • fopen - fine grained reading, for example synchronized or read and write IO.

Specialized functions:

  • curl - HTTP requests that go beyond simply reading or writing a file, for example ranged requests. curl may also offer superior performance for HTTP communications because the current implementation of php's http stream wrapper does not support transparent gzip encoding. curl does, and that may speed up downloads of textual data at the expense of CPU overhead.
  • fsockopen - Open a socket, i.e. direct network communication (not HTTP).

The above functions are ordered from specific to generic. Pick the first one in the list that matches your desired operation.


If you need to download something from somewhere and you have cURL on your server, stick to it. All the options are equally fast, but cURL is somewhat better on CPU and has nice additional features like support for compression and keep-alive. It'll will give you best results with peace of mind and minimal fuss.

If you don't have cURL, well, use built-in functions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜