Using Fsockopen() to check host status.  Times out randomly??

Posted on 2006-04-25
Last Modified: 2008-01-09

I have a while loop that does the below for about 90 times to a list of addresses.  I have it printing to tables on a page, which works fine.  However, everytime I run it, it times out at a different spot, regardless of whether the host is offline, online -- which is very strange to me.  I tried using Fclose(), but it said it was invalid (not stream).  

Does anyone know the best way to check port status for about 100 IP's w/ having it "time out" ?  

I did notice it's happening at EXACTLY 30 seconds everytime... I guess I'll check the PHP.INI.


      $VncCheck = @fsockopen($HostName, $VncPort, $errnovnc, $errstrvnc, 1);
                                if (!$VncCheck) {
                                                $VncStatus = 'OFFLINE';
                                                $VncStatusColor = '"#FF0000"';      
                                } else {
                                        $VncStatus = 'ONLINE';
                                                $VncStatusColor = '"#33CC00"';

Question by:jgantes

    Author Comment

    Never mind...  Just set this:

    max_execution_time = 30


    LVL 9

    Accepted Solution

    Default time for script is 30 seconds. If your script is running longer you should set higher time limit
    for your main script.

    To do that add this at the beginning of your script


    set_time_limit(500); // seconds

    // your code...



    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now