Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:35:58+00:00 2026-05-31T04:35:58+00:00

According to the description of the Google Custom Search API you can invoke it

  • 0

According to the description of the Google Custom Search API you can invoke it using the GET verb of the REST interface, like with the example:

GET https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=lectures

I setup my API key and custom search engine, and when pasted my test query directly on my browser it worked fine, and I got the JSON file displayed to me.

Then I tried to invoke the API from my PHP code by using:

$json = file_get_contents("$url") or die("failed");

Where $url was the same one that worked on the browser, but my PHP code was dying when trying to open it.

After that I tried with curl, and it worked. The code was this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);

Questions:

  1. How come file_get_contents() didn’t work and curl did?
  2. Could I use fsocket for this as well?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:35:59+00:00Added an answer on May 31, 2026 at 4:35 am

    Question 1:

    At first you should check ini setting allow_url_fopen, AFAIK this is the only reason why file_get_contents() shouldn’t work. Also deprecated safe_mode may cause this.

    Oh, based on your comment, you have to add http:// to URL when using with file system functions, it’s a wrapper that tells php that you need to use http request, without it function thinks you require to open ./google.com (the same as google.txt).

    Question 2:

    Yes, you can build almost any cURL request with sockets.

    My personal opinion is that you should stick with cURL because:

    • timeout settings
    • handles all possible HTTP states
    • easy and detailed configuration (there is no need for detailed knowledge of HTTP headers)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to Apple's description, the aurioTouch sample app is suppose to get the audio
Android: I am using following code to insert image into album According to description
I developing an application which works with Google API, according to my understanding. def
According to MSDN BOL (Books Online) description on SOME | ANY (Transact-SQL) , SOME
According to what I have found so far, I can use the following code:
Description According to the explain command, there is a range that is causing a
According to the following description I have to frame a CASE...END statement in SQL
According Martin Fowler's Unit of Work description: Maintains a list of objects that are
According to this , you can make use of xs:key and xs:keyref when marshalling
Is Eventbus more a Mediator or an Observer? According to Google, eventbus mediator gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.