S
S
slava kk2020-01-29 08:41:59
PHP
slava kk, 2020-01-29 08:41:59

How to get the amount of free space on the server via ssh and send to php?

How to connect in php via ssh, and find out the amount of free disk space on the server and send it to php?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
FanatPHP, 2020-01-29
@slavchickalpha

The easiest way is to get an SSH key to log in without a password, and write in php and then parse $out;
$out = shell_exec("ssh [email protected] 'df -BM'");

Z
zorca, 2020-01-29
@zorca

You can use Deployer , Envoy , or just exec( ). But it is better to use some kind of agent that will constantly work on the server and give the information we need on a simple request to the selected port or on a regular basis, via the API. Well, for example, on the server we create a cron task that will run a console php script once an hour and put the information into a json file. Then we can get disk space with a simple request to this json, without suffering from ssh requests to the server and without opening a potential security hole.

E
Eugene, 2020-01-29
@Nc_Soft

It is better to use zabbix for these purposes
. It has api and packages for php

S
Sergey Pliskin, 2020-01-30
@pligin

Why connect to SSH?
Why not ask PHP?
https://www.php.net/manual/en/function.disk-free-s...
disk_free_space
(PHP 4 >= 4.1.0, PHP 5, PHP 7)
disk_free_space - Returns the amount of available space in a directory or file system

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question