php - Handle CURL headers before downloading body -


Using PHP and curl (unless there is a better option in this case), is it a php function file Does the header handle the response before downloading?

For example:

I have a script that downloads and processes the URL of the user. I would like to add a check that if the file is not valid for my process (a text file, too large, etc.), the curl request will be canceled before the file is downloaded to the server.

Update: Solution Peer class HTTP_Request2: Allows you to set supervisors the ability to set the connection and cancel at any time. Works perfectly for my needs!

Using curls, requesting an HTTP HEAD to check for the header, if it is valid (Position is 200) Full HTTP GET request.

The original option that you must set is CURLOPT_NOBODY , which request HEAD

  curl_setopt ($ ch, CURLOPT_NOBODY, true);  

Then after performing the query, you need to check the return status which

  $ status = curl_getinfo ($ ch, CURLINFO_HTTP_CODE) is used. Can be done by;  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -