This is a simple script that runs a shell command from PHP with the function system().
It sometimes happens that a command doesn’t close the stdin or stdout, resulting the system() function to halt and wait for it to finish…
This causes PHP to reach the 30 second time limit and kill the script.
This script runs it in the background and you could make your commands send their output to a log file and still having full control.
Read the code below how to use it.
You can compile it by placing the code into ’shellproxy.c’ and then compile it with the following command:
gcc -o shellproxy shellproxy.c
I hope this is something useful for you as it was for me.
#include
#include
#include
int main(int argc, char *argv[]) {
char command[1024];
int t;
if (argc == 1) {
printf("\nShell Proxy\n");
printf("By Marius van Witzenburg \n\n");
printf("You will mostly use this program from PHP or any other\n");
printf("webscripting language to background run programs\n\n");
printf("Usage:\n");
printf("- CLI:\n");
printf("shellproxy \" \"\n");
printf("shellproxy \" > redirect.txt\"\n");
printf("- PHP:\n");
printf("system('shellproxy \" &\"');\n");
printf("system('shellproxy \" > redirect.txt\"');\n\n");
}
command[0] = 0;
for (t = 1; t < argc; t++) {
strcat(command, argv[t]);
strcat(command, " ");
}
fclose(stdin);
fclose(stdout);
fclose(stderr);
system(command);
}
It would be nice if you keep my name mentioned into this code if you use it.
Ps. Donations are welcome
Tags: C, Code, Command, Php, Proxy, Return, Shell, Value