ik wil een gameserver starten vanuit php, maar als ik
<?php exec("/usr/binnohup /home/stino/hlds_run -PARAMS > /dev/null & echo $!"); ?>
doe werkt het niet, 'k krijg wel een pid terug (wat bedoeling is) maar die pid is van een proses dat niet bestaat of al afgesloten is voor ik kan controleren.

wat wel werkt is datzelfde command via apache user onder ssh:
# su apache
$ /usr/binnohup /home/stino/hlds_run -PARAMS > /home/stino/consolelog & echo $!

/home/stino/consolelog > krijg ik mooi de serverlog in zoals het hoort, en server draait, als ik dit doe via php is die log file wel aangemaakt maar leeg.
Je geeft wel twee verschillende commando's. De 1 werkt en de ander niet.
huh?
ow hier mistypt
<?php exec("/usr/bin/nohup /home/stino/hlds_run -PARAMS > /dev/null & echo $!"); ?>


kijk men script:
<?php
/**
* @author Ashraf M Kaabi
* @name Advance Linux Exec
*/
class exec {
/**
* Run Application in background
*
* @param unknown_type $Command
* @param unknown_type $Priority
* @return PID
*/
function background($Command, $Priority = 0){
if($Priority)
$PID = shell_exec("/usr/bin/nohup nice -n $Priority $Command > /dev/null & echo $!");
else
$PID = shell_exec("/usr/bin/nohup $Command > /dev/null & echo $!");
return($PID);
}
/**
* Check if the Application running !
*
* @param unknown_type $PID
* @return boolen
*/
function is_running($PID){
exec("ps $PID", $ProcessState);
return(count($ProcessState) >= 2);
}
/**
* Kill Application PID
*
* @param unknown_type $PID
* @return boolen
*/
function kill($PID){
if(exec::is_running($PID)){
exec("kill -KILL $PID");
return true;
}else return false;
}
};
?>


<?
$execute = new exec();
$execute->background("/home/stino/rtcwet01/et +set map oasis +set dedicated 2 +set net_port 27203 +set fs_homepath "/home/stino/" +set net_ip 82.192.72.49");
?>

misschien om het nog absurder te maken:
<?
$execute = new exec();
$execute->background("sleep 100");
?>
kan ik wel terug vinden in ps axu | grep apache
$execute->background("/home/stino/rtcwet01/et +set map oasis +set dedicated 2 +set net_port 27203 +set fs_homepath "/home/stino/" +set net_ip 82.192.72.49");

Dit gaat niet goed door de quotes.

Edit: Probeer dit eens:
$execute->background("/home/stino/rtcwet01/et +set map oasis +set dedicated 2 +set net_port 27203 +set fs_homepath \"/home/stino/\" +set net_ip 82.192.72.49");
ja zeg, boel komt uit db dus quotes doen er niet toe
Okee, ik wist niet dat je kwaad werd...
Maar "bla bla "blo blo" en nog een bla" wordt door php niet als één string gezien.
kwaad?
mja, met of zonder: kijk;
als dit in de database staat:

/home/stino/rtcwet01/et +set map oasis +set dedicated 2 +set net_port 27203 +set fs_homepath "/home/stino/" +set net_ip 82.192.72.49

dan doe ik
$execute->background($db->command);
als je echo $db->command doet krijg je toch ook de juiste output

het ergerd me gewoon dat ik al 3 dagen daar op zit te zoeken.


misschien als je een betere manier weet om een gameserver te stoppen/starten via een website mag je het me altijd zeggen.

Reageren