Cheung
Cheung

Reputation: 15552

CURL vs fopen vs fsocketopen?

I would write a WordPress plugin to parse all image source and check it's broken link or not. My idea is :

  1. Select all post&page's images by regex from MySQL
  2. Navigate the image url and get the response header (404 ,403 error etc)
  3. print a report

Since i don't need actual to download the binary file, so in performance ,compare in CURL , fopen , fsocketopen Which one is worst to use?

And one more question, which method can execute in multi-thread?

Upvotes: 0

Views: 3390

Answers (1)

Yacoby
Yacoby

Reputation: 55465

The cost of opening a connection to the remote server makes the performance of the library a fairly moot point. In other words it isn't worth worrying about the performance of the functions.

A better option would be to use wse whatever function allows you to make HEAD requests (Which only return the HTTP headers). While you can do it with fsockopen (I don't know about fopen), it is a lot of work when cURL has code already written to send the request and parse the response.

For an example of how to do a head request using cURL see this answer.

And one more question, which method can execute in multi-thread?

PHP doesn't have threads

Upvotes: 4

Related Questions