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 8834857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:07:23+00:00 2026-06-14T09:07:23+00:00

I have written this simple piece of code : $ch = curl_init(); //Set options

  • 0

I have written this simple piece of code :

$ch = curl_init();

//Set options
curl_setopt($ch, CURLOPT_URL, "http://www.php.net");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$website_content = curl_exec ($ch);

In my case $website_content comes as false.
Can anyone suggest/advice something what could be going wrong?

  • 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-06-14T09:07:24+00:00Added an answer on June 14, 2026 at 9:07 am

    Error checking and handling is the programmer’s friend. Check the return values of the initializing and executing cURL functions. curl_error() and curl_errno() will contain further information in case of failure:

    try {
        $ch = curl_init();
    
        // Check if initialization had gone wrong*    
        if ($ch === false) {
            throw new Exception('failed to initialize');
        }
    
        // Better to explicitly set URL
        curl_setopt($ch, CURLOPT_URL, 'http://example.com/');
        // That needs to be set; content will spill to STDOUT otherwise
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // Set more options
        curl_setopt(/* ... */);
        
        $content = curl_exec($ch);
    
        // Check the return value of curl_exec(), too
        if ($content === false) {
            throw new Exception(curl_error($ch), curl_errno($ch));
        }
    
        // Check HTTP return code, too; might be something else than 200
        $httpReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
        /* Process $content here */
    
    } catch(Exception $e) {
    
        trigger_error(sprintf(
            'Curl failed with error #%d: %s',
            $e->getCode(), $e->getMessage()),
            E_USER_ERROR);
    
    } finally {
        // Close curl handle unless it failed to initialize
        if (is_resource($ch)) {
            curl_close($ch);
        }
    }
    

    * The curl_init() manual states:

    Returns a cURL handle on success, FALSE on errors.

    I’ve observed the function to return FALSE when you’re using its $url parameter and the domain could not be resolved. If the parameter is unused, the function might never return FALSE. Always check it anyways, though, since the manual doesn’t clearly state what "errors" actually are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this simple c code in microsoft visual c++ 2010. #include<stdio.h> #include<conio.h>
I have a simple plugin system in a piece of code I have written.
I have a problem with a very simple piece of code written in Javascript,
This is a simple script I have written to test command line argument handling:
I have written grammar for a language (sample code below) //this is a procedure
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I have written this code what it does is if user types postcode or
I have written this code outside all functions: int l, k; for (l =
I have written the following piece of code that reads through a given xml-file

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.