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 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题