Best Practices for making Web/Http Requests


I believe this is a very simple question. However, I have been searching for over an hour to little success.

Within my application I need to make a web request to a URL. For example, I may want to get some event data from a Facebook event (in which case I should somehow make a request to https :// and in return I’ll get some JSON with the data I need). I want to do a basic HTTP GET request. But, I can’t figure out how to do this.

My questions are:

  1. How do I make a HTTP GET request using best practices?
  • For example, I could use cURL, but that seems more console oriented. I could use file_get_contents but that seems hacky. Are there other ways?
  1. Is there a Yii way of making such a request?

As REST-ful APIs seem to be such a big part of web-development, I can’t imagine there isn’t a simple way to do this. And, to be honest, I’m kind of embarrassed to ask!

Thank you for your help.

I’ve really enjoyed my (small) development with Yii. On top of being a great framework (I did an extensive search about 8 months ago), it has taught me a lot.

I don’t sure if file_get_contents will always work… cause sometimes in php.ini foreign include is disabled…

I have same issue…what seems to be obvious, I just don’t see a good way to do this.

I can make ajax calls from within a controller but not sure how to make a call to return JSON data from an external



check out this:

Thanks !

I had not seen the curl extension. I will review.

Is the ehttpclient what I am looking for? Maybe !

Thank You !

That is just what is needed for this !