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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:29:46+00:00 2026-06-13T02:29:46+00:00

I have a simple cURL script that works just fine. But I’m curious about

  • 0

I have a simple cURL script that works just fine.
But I’m curious about how to detect a bad Url. And by “bad” I mean a non-existant URL, or if the server I am calling is down for a period of time, or I made a mistake and entered the wrong URL. (just examples)

here’s what I have so far:

<?php

$url = 'http://someurl_or_ip.com/some_file.php';
$post_fields = "type=whatever";
$post_fields .= "&first=".$first;
$post_fields .= "&last=".$last;


$ch = curl_init($url); // create a new cURL resource 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);   
curl_setopt($ch, CURLOPT_TIMEOUT, 1800);  

// Execute the request. 
$raw_response = curl_exec($ch); 
$succeeded  = curl_errno($ch) == 0 ? true : false; 

echo $raw_response;

?>

typically the $raw_response is something I can parse and use for other things, like how I want to display data to a user.

I simply replaced $url with a non-existent file (but to a valid domain), and I get “Not Found….The requested URL…..was not found on this server…”

Does this mean I need to parse this apache server message to know it’s not a good URL? Or does cURL have a way to detect it, via header information?

  • 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-13T02:29:48+00:00Added an answer on June 13, 2026 at 2:29 am

    You can look at the HTTP response code in the header, which will be 404 for a file not found:

    $http = curl_init($url);
    $result = curl_exec($http);
    $http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);
    curl_close($http);
    echo $http_status;
    

    If the server is not available, you obviously won’t get a response from the server at all, thus no HTTP response code. In this case curl_exec() would return with false, in which case you can handle the error:

    if(curl_exec($ch) !== false) {
        // Success
    } else {
        // Error
        $error_str = curl_error($ch);
        $error_num = curl_errno($ch);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple server script that just echos a line: <?php echo Server
I have found this little script in PHP that send a simple request to
I have a simple script that takes a subject-line and return-path from STDIN (a
I have a simple bash script that uploads files to an FTP. I was
I have simple php validation form that is halfway working. If you leave the
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require
I have simple win service, that executes few tasks periodically. How should I pass
I'm trying to write a simple bash script that accepts all arguments and interprets
I have written a Perl script that runs as a daily crontab job that
I have a PHP script that syncs data with a third party service, and

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.