Apache+PHP Help

Status
Not open for further replies.

alib_i

Cyborg Agent
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
*img32.exs.cx/img32/5198/desktop9mx.th.jpg
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
 

Deep

Version 2.0
need to rush now..
gonna take a look at this when i m back home i.e. after 2 hrs approx..

Deep
 

Deep

Version 2.0
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
 
OP
alib_i

alib_i

Cyborg Agent
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 *www.phpfreaks.com/quickcode/code/339.php
and here *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
 

Deep

Version 2.0
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
 

Deep

Version 2.0
alib_i said:
thnx deep ..
i think i'll have to approach a specialist !! :lol:

-----
alibi

but don't forget to post your reply here so that i can also know the solution...

Deep
 
Status
Not open for further replies.
Top Bottom