1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

Apache+PHP Help

Discussion in 'QnA (read only)' started by alib_i, Dec 13, 2004.

Thread Status:
Not open for further replies.
  1. alib_i

    alib_i New Member

    Joined:
    Jun 24, 2004
    Messages:
    1,191
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    omnipresent
    I run a web-server for my local LAN ..
    it runs on Apache+PHP (no MySQL)

    now, ..
    I have a page where I list (almost) all the HTTP/FTP servers on LAN

    The PHP code I use looks like this ->
    Code:
    $fp = fsockopen($ftp[$i],21,$errno,$errstr,0.02); 
    if(!$fp) { $success=2; }
    fclose($fp);
    if($success!=2){ 
    echo"<img src=online.gif border=0>
    ....
    ... }
    else 
    { .... }
    
    That port 21 is for FTP and I replace it with 80 for HTTP
    That $ftp[$i] is an array containing all ip addresses I am listing.
    This code runs in Loop for all ip addresses

    PHP Code runs very fine and correct ..

    The only problem I observe is this
    [​IMG]
    Every time someone accesses my webpage ..
    Apache opens a new socket on a NEW LOCAL PORT and port 21 or 80 of IP which im pinging

    After few hours I see that Apache is listening on 20-30 Ports ...
    it eats up quite a bit of memory ...

    Any Idea wht changes shud i bring to my code so that this doesnt occur!!!

    -----
    alibi
     
  2. Deep

    Deep Version 2.0

    Joined:
    Jan 23, 2004
    Messages:
    977
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mumbai
    need to rush now..
    gonna take a look at this when i m back home i.e. after 2 hrs approx..

    Deep
     
  3. OP
    OP
    alib_i

    alib_i New Member

    Joined:
    Jun 24, 2004
    Messages:
    1,191
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    omnipresent
    i'll be waiting ......... :lol: :lol: :lol:

    -----
    alibi
     
  4. Deep

    Deep Version 2.0

    Joined:
    Jan 23, 2004
    Messages:
    977
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mumbai
    a

    sorry for replying late....

    since you have xx no of ips then it is going to open each connection for one IP and then close it...

    so 2 visitors at the same time then u will see double conections open...

    the way can be use some cache or something..

    one way to do is will be...

    whenever you open any socket for ip

    do this...

    write this in one text file...

    IP Address Status & timestamp

    so when next user comes

    do this...

    compare current time stamp with the one provided in the file...

    and set some limit...say

    if current timestamp and file timestamp has gap of say less than 1 min then show status from file

    else do fsock...

    so this will not open too many sockets and make the job easier...

    u can do the same using mysql also...

    i am not pasting the code coz i think you must have aware of how to do it...

    but this is just my logic....i have not used fsockopen in my life... but my logic says this should do the job...

    you may ask in the forums like www.sitepoint.com or www.phpfreaks.com and see what they have to say and then share it here :)

    take care
    Deep
     
  5. OP
    OP
    alib_i

    alib_i New Member

    Joined:
    Jun 24, 2004
    Messages:
    1,191
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    omnipresent
    hi deep

    Wht you say is that I try to cache the results so that less number of sockets are create in all.

    I had thought over that possibility earlier .. but complicates the php script by many folds and doesnt give much profit.

    Wht i do is .. that i display realtime info abt which sites in LAN are up and which are down.. HTTP sites.. FTPs and Radios, etc ..
    a kind of directory of all that is in LAN

    and fsockopen is a simple and quite standard script to check if a website is currently running or not ..
    look here http://www.phpfreaks.com/quickcode/code/339.php
    and here http://uk.php.net/manual/en/function.fsockopen.php
    very commonly used

    The only problem is that .. i cannot specify which LOCAL port shud the script use. I can only specify REMOTE port. So it keeps on using newer newer LOCAL ports .. and keeps loading my system ;)

    Currently I simply do a 'net stop apache' and then 'net start apache' to reset the apache service to normal..
    but its not a solution ..

    And yes ..
    It seems phpfreaks require login ..
    If you have a login .. then plz post my problem there ..
    I'll keep looking at other places too

    Thnx
    -----
    alibi
     
  6. Deep

    Deep Version 2.0

    Joined:
    Jan 23, 2004
    Messages:
    977
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mumbai
    Ali,
    what i meant was i have never used it, i knew what it does :)

    anyways i tried it on my local machine..

    it closes the socket once it has done checking it...and i dont think there is any way other than caching the results to avoid opening diffrent ports on local machine...

    phpfreaks and sitepoint registration is free...ppl are very helpful there..

    cheers
    Deep
     
  7. OP
    OP
    alib_i

    alib_i New Member

    Joined:
    Jun 24, 2004
    Messages:
    1,191
    Likes Received:
    2
    Trophy Points:
    0
    Location:
    omnipresent
    thnx deep ..
    i think i'll have to approach a specialist !! :lol:

    -----
    alibi
     
  8. Deep

    Deep Version 2.0

    Joined:
    Jan 23, 2004
    Messages:
    977
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mumbai
    but don't forget to post your reply here so that i can also know the solution...

    Deep
     
Thread Status:
Not open for further replies.

Share This Page