views:

109

answers:

2

I have a dedicated server that I use to crunch lots of data. The way I have it now, I can open a script with a process ID like example.php?ex_pid=123 and just let it go. It downloads a small portion of data, processes it, then uploads it into a database then starts again.

Ideally, I would like to call example.php?ex_pid=123 directly and not by passing a variable to example.php like exec('./example.php'.' '.EscapeShellArg($variable)); to keep it from acting globally.

I don't care about the output, if it could execute in the background, that would be brilliant. The server is an Ubuntu distribution btw.

Is this even possible? If so, any help and examples would be more then appreciated.

A: 

The main issue with that is that ?ex_pid is GET data which is generally associated with either including the file or accessing it through a browser. If you were including the file or accessing it from a web browser this would be trivial, but running it as CLI, your only option would be to pass it as an argument, unfortunately. You can pass it as ex_pid=123 and just parse that data, but it would still need to be passed as an argument but doing that you could use parse_str() to parse it.

Depending on what the script does, you could call lynx to call the actual page with the get data attached and generate a hash for an apikey required to make it run. Not sure if that is an option, but it is another way to do it how you want.

Hope that helps!

Brad F Jacobs
A: 

You could do something like:

exec("./example.php '".addslashes(serialize($_GET))."');

And then in example.php do something like this:

count($_GET) == 0 && $_GET = unserialize(stripslashes($_SERVER['argv'][1]))
Shaun