2014-07-03 48 views
-1

在我问这个问题之前,我会解释一下这个设置。PHP - 在远程服务器上Ping另一个PHP文件

服务器1: VPS在CentOS
服务器2: VPS在CentOS

在server1上我有/var/www/html/test.php 此文件必须ping通get.php上其他服务器,有一些POST变量。

Server2上我有/home/somedir/get.php

所以是能ping通一个文件,这是不是webfile?

+0

PHP可以作为一个命令行脚本来执行,所以是的,这是可能的。 –

+0

定义'ping'。你的意思是一个HTTP POST请求? – reto

+0

就这样它运行server2上的文件 – user3802123

回答

0

SSH通过ssh2_exec()进入server2。来自php.net的修改示例:

<?php 
$connection = ssh2_connect('server2.example.com', 22); 
ssh2_auth_password($connection, 'username', 'password'); 

$stream = ssh2_exec($connection, 'php /home/somedir/get.php'); 
?> 

上面的文件应该放在server1上。

来源:http://php.net/manual/en/function.ssh2-exec.php

相关问题