doumei1203 2010-02-23 21:25
浏览 25
已采纳

需要代码来执行存在于多个服务器上的单个php脚本(不离开调用页面)

I've got an updater.php script located on several of my sites. This updater.php file is set to execute code when called from a home base (my central server).

So I'm looking to create a dashboard of sorts in which all my remote site addresses are listed, with the path to this updater.php script like so...

www.server1.com/path/updater.php
www.server2.com/path/updater.php
www.server3.com/path/updater.php
...etc (there will be lots of them)

And I'll create an interface to list those along with checkboxes beside each one, and a select all, etc

And I'm looking to create a PHP script that will iterate over the whole collection of urls in that list and execute the call to the updater.php file on each server, passing it a "version=v001" for example...

$.get("http://server1.com/path/updater.php?version=v001");
$.get("http://server2.com/path/updater.php?version=v001");
...etc

I've already set up the code in updater.php (the file that resides in all my sites) so that when it receives a request, it parses the $_GET['version'] to see what the version is and it knows which file to go get on my central server to perform the update.

I'm just looking for some clues how to create the script for this dashboard that sets it all into motion...

PS: In total, this is basically a batch updater script that executes wordpress theme updates without having to go to each site and do them individually.

  • 写回答

4条回答 默认 最新

  • douwaz34842 2010-02-23 21:37
    关注

    You might wanna check PHP's cURL extension which allows you to send request to multiple sites within your script quite easily.

    If you need further assistance, let me know - I'll edit.

    EDIT

    You could use one of the javascript frameworks that would allow you to easily manage your AJAX calls (i.e. jQuery - imho the most stringent). Then do something similar to:

    <form name="updater" id="updater" ...>
        <input type="checkbox" name="server[]" value="0"/> Server 1
        <input type="checkbox" name="server[]" value="1"/> Server 2
        ...
    </form>
    
    <script type="text/javascript">
        var server_url = [
            'www.server1.com/path/updater.php',
            'www.server2.com/path/updater.php',
            'www.server3.com/path/updater.php'
        ];
    
        $('#updater').bind('submit', function() {
            $('input[name="server[]"]:checked', this).each(function() {
                $.get(server_url[this.value]);
            });
        });
    </script>
    

    Here you go!

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

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算