I have a PHP application that returns forecasts values to a client in a json format. I hold all the data as i am collecting more in a variable.
If the client only requests values from a short period of time, life is good and he gets what he asked for. The problem is when he requests 1 or more years of forecasts. The exaust memory errors appears because the dataset stored in the variable is huge.
I don't want to extend memory, im thinking in alternative ways of doing it.
I came across with memory mapped file. Is that a good solution or you can think of others? Thank you!
Im using gearman and for each data retrieved by a worker a new array with values is added to my forecast variable.
Once all is finished i return it to client.
public function requestCompleteApi(\GearmanTask $task)
{
$this->forecast[] = unserialize($task->data());
}