Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to fetch the contents of a remote file. Which is better for performance - wp_remote_get, file_get_contents, or cURL?

How exactly does wp_remote_get work? Can you suppress errors, ex. @wp_remote_get ?

Thanks

share|improve this question
    
If you get errors, then please add the details of the errors to your question. Half a question is no question at all. –  Otto Mar 31 '13 at 6:01
add comment

1 Answer

Always use wp_remote_get when in a WordPress context. It figures out the correct way, be it curl or something else, and uses that. Simple.

share|improve this answer
    
Is it possible to supress errors with an '@' like other functions? Also, is it possible that wp_remote_get is not allowed on a server, but file_get_contents is allowed? How could I go about writing a function that uses file_get_contents if wp_remote_get gives an error? Thanks! –  Mike Mar 31 '13 at 3:10
    
To elaborate the HTTP API uses $request_order = array( 'curl', 'streams', 'fsockopen' ); so curl first if that fails streams then fsockopen. Errors are up to you how you handle them. –  Wyck Mar 31 '13 at 5:24
    
Without more information on the error, it's impossible to answer your question in any more detail. Make your question more explicit and clear. Additionally, you don't want to use file_get_contents, because that won't work on a majority of webhosts. If you get an error, then tell us the error so that we can give you correct information instead of guessing randomly at your problem. –  Otto Mar 31 '13 at 5:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.