Okay I will make this brief.

I have used PHP before, and Perl before. I am currently running a website on a shared host, which I don't have physical access to. I only have FTP access, nothing else. It runs both PHP and Perl, in addition to others.

I have a Perl bot I am currently running of my own computer, which I don't want. It is a bot which connects to an IRC network, and then runs an idling RPG based on Stargate SG-1, see my homepage for more details if you need to. This Perl bot would be much more useful run from the host server my site is on. Which I was told I have permission to do by the hosting company. But as I have no SSH or virtual desktop or anything, I can't just run the bot. So I was told I could make a php page which would run the bot.

I, however, have no clue how to do this, however easy or complicated it may be.

The problem is, I need to have my bot running on a web server, so I can access the db it uses and 2 other files to populate some of the info on the webpage it accompanies. Including map locations, characters, and quest info.

I know it can be run, and only uses about 250k a day, so that usage isn't of concern to me. However, without a way to start the bot, I have no to way run it.

http://www.cosmicpothole.com/IdleSG/index.php

    The functions in php for running external programs are [man]exec[/man], [man]system[/man] and [man]passthru[/man]. There are some examples in php manual for them. The difference is exec doesn't display output automatically, system outputs results to browser and passthru outputs binary results (images for example).

      And will any of the 3 run something constantly? What I really want is something where I can just run it once, then close the page without stopping the bot and letting it that bot run indefinitely.

      If I have to keep a page open, it means I have to keep my computer on, and my computer running, which defeats 1/2 of the purpose of hosting the bot on a server.

      I don't think I need any output, being as it will be logging into IRC and it has plenty of commands once there, I will be okay.

        I haven't tried it, but I suppose the program won't stop until it ends, even though you'll close the page.

        Just noticed in exec manual (have you looked at it?)

        Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.

        EDIT: And another quote from comments to manual:

        If you want to run somenthing but php just keep processing data and don�t answer until the program is closed (run in background mode, without interfering the program), from the note ( If you start a program using this function ... PHP will hang until the execution of the program ends ), jonas function will certainly be useful for you:

        <?php
        function execInBackground($path, $exe, $args = "") {
           global $conf;
        
           if (file_exists($path . $exe)) {
               chdir($path);
               if (substr(php_uname(), 0, 7) == "Windows"){
                   pclose(popen("start \"bla\" \"" . $exe . "\" " . escapeshellarg($args), "r"));   
        } else { exec("./" . $exe . " " . escapeshellarg($args) . " > /dev/null &");
        } } } ?>

        Thank you Jonas. It has been very useful for me.

        Amazing things can be found when you actually spend some time looking 😉

          I did read it.

          The output of the bot is into seperate files, and into the IRC window, so that shouldn't hang. And it doesn't have an end.

          But the way I read it wasn't that it said you can leave the program running, just the page running. That was the just of it from what I gathered. And it mentions that PHP would hang assuming the bot's output wasn't to external files, in theory here for what I want, PHP couldn't hang. It would basically just remotely start the Perl bot and close. Then the Perl bot would continue running in the background.

          I was under the impression that normally said type of calls would run the program called only as long as the page required it. Once closed or finished, I had thought PHP would terminate the program. It would appear that is the normal way to keep serverside memory and processes from being overwhelmed.

          I will expermient and make sure it would stay open. I guess I hadn't considered the alternative reading of that note.

          EDIT:

          Okay, I see Jonas's and again they mention PHP hanging. Can you see where I would think perhpas that isn't exactly what I was looking for? PHP shouldn't be able to hang if I can just run a program once and close out the page because PHP will cease running.

          2nd Edit:
          $WshShell = new COM("WScript.Shell");
          $oExec = $WshShell->Run("cmd /C dir /S %windir%", 0, false);

          Looks closer to what I want...Then I can just run my program, assuming I knew I knew the real and not virtual path of the file.

            Write a Reply...