【问题标题】:PHP - Ping another PHP file on a remote serverPHP - Ping 远程服务器上的另一个 PHP 文件
【发布时间】:2014-07-03 23:02:18
【问题描述】:

在我问这个问题之前,我会解释一下设置。

服务器 1: 使用 CentOS 的 vps
服务器 2: 使用 CentOS 的 vps

在 server1 我有 /var/www/html/test.php 该文件必须 ping 另一台服务器上的 get.php,并带有一些 POST 变量。

在 server2 上我有 /home/somedir/get.php

那么是否可以 ping 一个不是 web 文件的文件?

【问题讨论】:

  • php 可以作为命令行脚本执行,所以是的,这是可能的。
  • 定义ping。您是指 HTTP POST 请求吗?
  • 就这样在 server2 上运行文件
  • 是的。当您在 http 中查看 test.php 时,它会在另一台服务器上运行 get.php。
  • 在 server1 上创建一个 php 文件,在该文件中,您使用 curl 打开 server2 上文件的 url。如果无法远程访问,请使用 telnet 或 ssh 通过 php 脚本登录.

标签: php centos


【解决方案1】:

通过 ssh2_exec() SSH 到 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

【讨论】:

    猜你喜欢
    • 2019-01-28
    • 2012-09-16
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    相关资源
    最近更新 更多