duandi8544 2012-03-31 11:53
浏览 70
已采纳

什么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?

  • 写回答

1条回答 默认 最新

  • doutusheng5879 2012-03-31 12:43
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序