I have got script which generates some graphic and returns it as a result, also it caches this graphics etc.
I use symfony2 and in a controller I need to invoke this script, for now I use this function, to invoke my php script:
private function http_post($url, $data)
{
$data_url = http_build_query ($data);
$data_len = strlen ($data_url);
return array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'POST'
, 'header'=>"Connection: close\r\nContent-Length: $data_len\r\nContent-Type: application/x-www-form-urlencoded\r\n"
, 'content'=>$data_url
))))
, 'headers'=>$http_response_header
);
}
I think this way isn’t the best and as I remember well file_get_contents is pretty slow?
So my question: is it good way to send POST to this script via “http_post”? If not, than what would be better?
EDIT: I don’t want to have this script in a controller, so no include solutions please :).
If you wish to implement the image generator as a controller, you would just return the response as normal:
return new Response($generated_image);.So this could be your controller:
Then, you can call your image generator from any controller using
forward()