简体   繁体   中英

How can I Connect to other server

I want to make a platform to get disk space usage of several server. How i can do it?

$df = disk_free_space("/");

i want this line of code to be executed on my all servers

仅使用php并非易事,甚至不可能,我认为最好的解决方案是将带有curl的请求发送到服务器,以返回磁盘空间使用率。

One way is to use the ssh2_XXX functions of PHP to login to each server and run df / .

Another way is to create a web page on each server that runs disk_free_space('/') and echoes the result. Then you can use file_get_contents("http://servername/disk_free.php") to query each server.

There are many ways to do this. Curl is an option, you can use cron on each server, that runs at specific time and updates the value to a web server, or you can use ssh to get the same info.

on each server, you can insert a page that returns the free space:

GetFreeSpace.php

<?php
echo disk_free_space("/");

You can use cURL to query several servers

<?php
$ch = curl_init();

curl_setopt_array($ch, array(
    CURLOPT_URL => 'http://server1.com/GetFreeSpace.php',
    CURLOPT_RETURNTRANSFER => true
));

echo curl_exec($ch);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM