douyakan8924 2012-07-09 10:36
浏览 141
已采纳

创建使用php连接外部服务器的接口(并执行shell命令)

I have 4 servers for web, dns, mail and database. I wanna to create an interface to remotely connect those servers using server's IP (may be port) and username and password(and later, in next step execute linux/winsows commands such as shutdown/reset server, stop/start IIS, stop/start mail server, ...)

Is it possible or any link to help me?

  • 写回答

2条回答 默认 最新

  • duanbohan2015 2012-07-09 12:58
    关注

    You can use ssh module as said by GeoPhoenix. You can try another method using curl. I assume you're using php, so consider following example,

    function check_dserver_process(){
        if(!$ch)
           $ch = curl_init();
    
    
            $options=array( CURLOPT_URL => "http://122.165.212.22:81/mysite/init.php",
                            CURLOPT_FRESH_CONNECT => 1,
                            CURLOPT_RETURNTRANSFER => 1, 
                            CURLOPT_FORBID_REUSE =>1,
                            CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01;Windows NT 5.0)"
                         );
    
            curl_setopt_array($ch,$options);
            $result=curl_exec($ch);  
            $op=($result===false ? curl_error($ch) : $result);
            curl_close($ch);
            return $op;
    }  
    

    If you call above function it will fetches the output from init.php from the given url. so you can run your own commands from init.php using exec() function. Before you start the process in init.php make sure the request came from one of your ip.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b