什么PHP脚本检查ftp服务器在线?

I need to write a php script which is called by a setInterval( "ajaxrequest('ftp.php', 'context')", 1000 ); function. The php script is fairly easy. It's countain an array of ftp addresses. It loop the array and check every ip address that is online or not.

Here is a sample code of the php script:

$conn_id = ftp_connect("192.168.1.108",21,1) or die ("Cannot connect to the server");
ftp_close($conn_id);

So basically what happens here: We have a javascript which calling a php script every second to check that the ftp servers are online or not. In the PHP script try to connect that if it cant it wrote out "Cannot connect to the server" then it closes the connection.

My problem is that i have to do this way, do not have any chance to use it by cron job because we need to check it trough a web page that the servers are online or not in real time. But in this way somewhere there is a memory leak its eats my memory really fast.

Is there any way that i can release the memory or solve this problem in an other way?

consider this answer to be a suggestion and direction, I never had to do such things, but if i wore to face it.

I would write a cron, that will scan the ftp port over an ip. This cron will run once every minute. The ftp's that are not responding will be kept in db.

I would make ajax requests to the php only to retrieve those data from the table.

What this will do is allow to asynchronously execute the two major tasks

  • List all ftp's not responding
  • update user with the list of ftp's not responding

Also, your method will have to find out list of ftp's not working for every instance, and this will put even more strain on the server when multiple requests will be made. This way will make the resource hungry execution once, which will be valid for all :D

hope this helps...

EDIT not sure if this adresses your cron dilemma, but do update