Jump to content

Having a problem running a background task


dabip

Recommended Posts

Hello, I'm trying to SSH into a remote Debian Linux Server, and run a server.

 

The server download is at: http://download.mtasa.com/deathmatch.html in case you wanted to test it out ;)

 

Anyway, here is the code I'm using:

 

My SSH Class built on top of SSH2

http://dabphp.pastebin.com/m1c5563

 

My Code utilizing it...

http://dabphp.pastebin.com/m2c0acf34

 

 

I have tried using nohup, and ./mta_server & and other things through PHP and it just won't stay running. I can run it, and keep it running in Terminal, but it just won't work in PHP. I can run things like apache(2), and other things that auto-fork into the background, just nothing that simply runs right where it's created. I hope I've included everything. This problem has been racking my brain for days now and it's just got me frustrated..

 

Anywho, thanks for taking your time to help out a frustrated 'ol php coder :P

Hmm that didn't seem to do anything either. I'm really thinking taht it's simply the process, and not our code.

 

I even tried running a remote script on in the path of the ./mta_server file itself.

 

<?php

 

 

echo run_in_background( "./mta_server" );

 

 

$fh = fopen( 'test.txt', 'w' );

fwrite( $fh, 'Hi' );

fclose( $fh );

 

 

function run_in_background($Command, $Priority = 0)

  {

      if($Priority)

          $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & ech$

      else

          $PID = shell_exec("nohup $Command 2> /dev/null & echo $!");

      return($PID);

  }

 

?>

 

It still failed to run into the background. :\ (I found that function on some website). It still wrote a file btw. So it was functioning correctly :\

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.