exec, shell_exec, system, ...?
ik wil een gameserver starten vanuit php, maar als ik
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.
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
kijk men script:
misschien om het nog absurder te maken:
kan ik wel terug vinden in ps axu | grep apache
ow hier mistypt
kijk men script:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?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;
}
};
?>
/**
* @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;
}
};
?>
Code (php)
1
2
3
4
2
3
4
<?
$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");
?>
$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:
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");
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");
Gewijzigd op 17/02/2006 21:28:00 door - SanThe -
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.
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.
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.
Gewijzigd op 17/02/2006 22:01:00 door Stijn




