0

I am new to PHP and web development. I am trying to build a basic Facebook application. Hence it is necessary to use Http Requests to get user data from Graph API within Facebook. I checked how to make requests with PHP yet I saw that Http request methods are not built-in. I understand that I need to install appropriate libraries to use them and everything was fine until I got that it is almost impossible to install Pecl or Pear to a hosting service(i am using Godaddy).

I have looked into lots of sites including Stackoverflow yet there are no answers. Plenty of sites explain how to install packages to a local server.

I could only tried Pear | go-pear.phar web installation yet it did not work. I do not know how to execute a .phar file even though I checked the documentation(Pear Installation Doc). This link, Installing Pear on Godaddy Hosting, explains what I have tried to do.

One more question, if it is not possible to install any of these packages, so how to I make HTTP Requests with PHP? Is there any other way?

Thanks for any answer.

msharpp
  • 379
  • 1
  • 6
  • 20

2 Answers2

1

php can do http requests, if allow_url_fopen is enabled. And there's always the CURL library (if enabled). You can test both with something as simple as:

$c = curl_init();
$txt = file_get_contents('http://google.com');

If curl's not installed, the first line fails. If url operations are disabled, then the second line will fail.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • I have just tried it seems working. However, just curiosity, why i need $c = curl_init() ? How do I use it for example? And will this allow me to make access token requests on Facebook? – msharpp Apr 28 '12 at 15:45
  • @msh just look at curl_init() documentation – Martin. Apr 28 '12 at 15:48
  • Also is it possible to use file_get_contents() without initializing Curl? – msharpp Apr 28 '12 at 15:49
  • 1
    yes, php's internal streams/url operations are independent of curl. And yes, it could do a token request, since it's just doing plain-jane HTTP operations. – Marc B Apr 28 '12 at 15:49
  • Thank you very much. One more thing, why then only packages explained on the PHP manual site and is it really impossible to install Pear/Pecl to a hosting without controlling it? Sorry if these seem ankward I just could not find an appropriate answer anywhere. Thanks. – msharpp Apr 28 '12 at 15:54
  • if it's a shared server, they're not going to let you install stuff into the server, since that could affect OTHER users of the server. – Marc B Apr 28 '12 at 16:21
0

Assuming the hosting you are using with Go Daddy is the Linux 4GH hosting, PEAR and Pecl should already be installed and available for use.

Mike_GoDaddy
  • 1,121
  • 1
  • 7
  • 9