drjltlm156790 2016-03-07 08:49
浏览 77

如何在没有SSH的情况下启动php脚本

I have an script that is supposed to run via cmd on a local machine using this command line: @php -c ./ StartBot.php %1

It's an script for a guild chat bot for an MMORPG.

This is the php code of StartBot.php

<?php
/*
* StartBot.php - Starts and restarts the bot
*
* BeBot - An Anarchy Online & Age of Conan Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2010 Thomas Juberg, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
* - Temar (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2009-01-23 09:21:51 +0100 (Fri, 23 Jan 2009) $
* Revision: $Id: StartBot.php 1959 2009-01-23 08:21:51Z temar $
*/

/*
Take a decent stab at what OS we run on and try using some sane defaults
*/
$os = getenv("OSTYPE");
if (empty($os))
{
    $os = getenv("OS");
}

if (preg_match("/^windows/i", $os))
{
    /*
    This default should work for Windows installs where php is installed to the bot directory.
    */
    $php_bin = "php.exe";
    $php_args = " -c ./ ";
    $main_php = "Main.php"; 

    /*
    If the above fails you can try specifying full paths, example:
    $php_bin = "C:\php\php.exe";
    $main_php = "C:\BeBot\Main.php";
    */
}
else
{
    /*
    This is a sane default for the php binary on Unix systems.
    If your php binary is located someplace else, edit the php_bin path accordingly.
    */
    $php_bin = trim(shell_exec('which php'));
    $php_args = " -c ./ ";
    $main_php = "Main.php";
}
$confc = TRUE;
require_once "./Sources/Conf.php";
if($argv[1] != $conf -> argv)
{
    echo "Use \"StartBot.php ".$conf -> argv."\" to start bot next time
";
    $argv[1] = $conf -> argv;
    $conf -> ask("Press Enter to load Bot");
    if(!$argv[1] || $argv[1] == "")
        $argc = 1;
    else
        $argc = 2;
}
if(!empty($conf -> pw))
{
    $pw = $conf -> pw;
    $conf -> pw = NULL;
}

// Create the command to execute in the system() call of the main loop:
$systemcommand = $php_bin . $php_args . " " . $main_php;
if ($argc > 1)
{
    $systemcommand .= " " . $argv[1];
}

while (true)
{
    if($pw)
    {
        $fp = fopen('./conf/pw', 'w');
        fwrite($fp, $pw);
        fclose($fp);
    }
    $last_line = system($systemcommand);

    if (preg_match("/^The bot has been shutdown/i", $last_line))
    die();
    else
    sleep(1);
}

?>

The problem is that I don't have SSH access from my cpanel.

Is possible to run this script via another php file or something?

Thanks

  • 写回答

1条回答 默认 最新

  • duanpanbo9476 2016-03-07 12:52
    关注

    Yes you can do this from another PHP file, to run a command on your server via PHP use the exec() command as so:

    <?php
    exec("@php -c ./ StartBot.php %1");
    ?>
    

    You can then run this file via your browser.

    You should try and get SSH access to your server though as a long-term solution this isn't the way to go, who is your host?

    Good luck

    Try this for live output:

    while (@ ob_end_flush()); // end all output buffers if any
    $cmd = "@php -c ./ StartBot.php %1";
    $proc = popen($cmd, 'r');
    echo '<pre>';
    while (!feof($proc))
    {
        echo fread($proc, 4096);
        @ flush();
    }
    echo '</pre>'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题