Closed uribes78 closed 6 months ago
The connection
property of the $req
will be deleted after the send()
call.
So you can store connection
to a variable. Codes like this.
$connection = $req->connection;
$connection->send( (new Response(200, ...);
$callback = function ($row) use ($connection) {
$connection->send( new Chunk( implode(',', (array) $row) ) );
};
Great, changing as you suggest it works that part. But I'm facing this, once the process sending chunk's has finished, I doing this:
$callback = function ($row) use ($connection) {
$connection->send( new Chunk( implode(',', (array) $row) ) );
};
$result = $bo->{$report}(QueryRequest::getInstance($req), $callback);
return (new Response(200))->withBody( new Chunk('') );
But, the browser is detecting a failed and abort the download, as you can see in this image:
the return line could be the problem?, I'm doing this, because I need to return a Response
object beacuse it's on middleware flow, and the last middleware expect to get a Response
object to send the last result
Any suggestion? Thanks
Well, I solved it, just changed like this:
$callback = function ($row) use ($connection) {
$connection->send( new Chunk( implode(',', (array) $row)."\n" ) );
};
$result = $bo->{$report}(QueryRequest::getInstance($req), $callback);
$connection->send( new Chunk('') );
return new Response(200);
Thanks anyway! Workerman
it's a great framework.
Hi, I'm developing a web service using th HTTP protocol and want to send a file using chunks
My code is:
but when a callback is executed and try to use the connection inside request I getting this error:
Worker[28498] process terminated with ERROR: E_ERROR "Call to a member function send() on a non-object
Am I doing something wrong? How can I send chunked part of a file (creating a CSV comming from database)
Hope you can give a glance! thanks.