In php-curl, is there any way of fetching the header, do some processing with it within the defined headerfunction, then cancel the request if certain conditions are met? The contents of the body is very large, so just discarding the data will waste bandwidth. Any suggestions?
Asked
Active
Viewed 806 times
1 Answers
1
You could assign a callback function to process the data using CURLOPT_WRITEFUNCTION.
Sources:
- http://curl.haxx.se/mail/curlphp-2008-03/0059.html
- http://php.net/manual/en/function.curl-setopt.php
EDIT
Returning an invalid length from the curl writefunction terminates the curl request.

Cameron Martin
- 5,952
- 2
- 40
- 53

matthiasmullie
- 2,063
- 15
- 17
-
Yes but I want to be able to terminate the connection with the remote server from within a header callback function, and therefore never receive the body. – Cameron Martin Nov 21 '11 at 16:10
-
1Not tested: from withing the header callback function, assign a variable in a more global scope a certain value when the fetching of the data should be terminated. Then, from withing the writefunction callback, check if that value is set. If yes, terminate by returning an invalid length; if not set: process the content in a good way. – matthiasmullie Nov 21 '11 at 16:15
-
You may also take a look at http://stackoverflow.com/questions/1378915/header-only-retreival-in-php-via-curl – matthiasmullie Nov 21 '11 at 16:17