How to solve the Fsockopen function, error

Source: Internet
Author: User
 


This is what I looked for in the Internet, take the remote file size example.
If the domain name is normal, the file size is returned.
If the domain name is normal and the file does not exist, it returns false.

Now the problem arises, if the domain name is not normal, like the above address, the domain name cannot be resolved, that is, inaccessible. The error message will be output at this time.

Php_network_getaddresses:getaddrinfo failed: Do not know such a host. In D:\PHPnow-1.5.6\htdocs\webadmin\inc\filesize.php on line 15

How can this error message be removed, in the case of not modifying the Web server configuration, only in the code to solve.
Because I want to use AJAX to fetch file size information. So can not error, an error, JavaScript gets the return value, is the wrong message, which led to the front desk can not run.

Is there a meeting, pointing at the younger brother.


Reply to discussion (solution)

Try
{
$fp = Fsockopen ($host, $port, $err _no, $err _str,30);
}catch (Exception $e)
{
}

Adding an exception handling is still not working.

$fp = @fsockopen ($host, $port, $err _no, $err _str,30);
Block out error messages (This function was born before exception handling)

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.