The User Uploads the image. After this step you can create a Task. One Taks is one row at the task table in your database.
class Task
{
const STATUS_PENDING = 'pending'
const STATUS_ERROR = 'error'
const STATUS_FINISHED = 'finished'
private $userid;
private $taskData = array();
public function run()
{
// create process
}
public function update()
{
// update the status an other changes you need to the database
// or any other storage you use.
}
public function getStatus();
}
class TaskManager
{
const MAX_TASKS = 5;
private $tasks = array();
public function addTaks();
public function start()
{
foreach ($tasks as $task) {
$task->run();
}
}
}
At the server side you've to think how to work / organize your tasks. This depends on your needs. With the power of a TaskManager you can
control your process. This is very important that not 100 process are running parallel.
The Client-Side can now easy ask the task table with the userid to check for pending task. If the status finished or error you can give the user
an excellent feedback. You can poll this information every five seconds. The interval depends on your need. A polling under five seconds can be odd for your
browser. Its a good idea that the client will fetch the status instead of the server will send the status to the client. If it is important that the server sends the status you've to use web sockets. The backend can be the same.
Here is a simple polling example.
setInterval(function(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json"});
}, 30000);
proc_open is only good if you've have some advanced options. With the power of proc_open
(have a eye on the pipes) and in combination with stream_set_blocking.
You can Write an async task handling. If you don't need some special exec
will be enough.
Here is a non-blocking example.
class Task
{
private $process = null;
private $pipes = array();
private $status = 'pending'
public function run()
{
$descriptor = array (
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$cmd = "/path/to/progam --with --some-arguments"
$this->process = proc_open($command, $descriptor, $this->pipes);
stream_set_blocking($this->pipes[1], 0);
}
public function close()
{
foreach($this->pipes as $pipe) {
fclose($pipe);
}
$exitStatus = proc_close($this->process);
$this->process = NULL;
return $exitStatus;
}
}
I hope this will gave you some inspiration to solve your problem.
For real message queues you can use what you want. I'm a fan of http://kr.github.io/beanstalkd/ I'll now stop with solutions and ideas cuz, this issue
is more complex and I can write another 100 pages. If you've konkrete questions, you can drop a line.