You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello,
I've severall custom controllers ; each function/route create the Response return by api->handle and send as Response to the call.
I'd like to make post operations (after the response has been send) that can be time consuming like reindexing DB or making backup (few seconds) and I don't want to block the response..
Of course, I could add this function to the last line of the my api.php
`<?php
namespace Tqdev\PhpCrudApi;
use Tqdev\PhpCrudApi\Api;
use Tqdev\PhpCrudApi\Config\Config;
use Tqdev\PhpCrudApi\RequestFactory;
use Tqdev\PhpCrudApi\ResponseUtils;
$config = new Config([
'driver' => CONF_driver,
'address' => CONF_address,
'port' => CONF_port,
'database' => CONF_database,
'username' => CONF_username,
'password' => CONF_password,
'cachePath' => CONF_tempDir,
'cacheType'=>'TempFile',
'controllers'=>'cache', //"records,status', // for /status/ping
//'middlewares'=>'', // cors disabled xsrf don't work with cors disabled ?
'middlewares'=>'cors', // for dev only
'customControllers' => 'eCtrl',
]);
$request = RequestFactory::fromGlobals();
$api = new Api($config);
$response = $api->handle($request);
ResponseUtils::output($response);
file_put_contents('request.log',RequestUtils::toString($request)."===\n",FILE_APPEND);
file_put_contents('request.log',ResponseUtils::toString($response)."===\n",FILE_APPEND);
`
but in this case, how to call in this case a function of eCtrl class (not a static one?)
The text was updated successfully, but these errors were encountered:
After different tries, and as I can't use pcntl_fork() on my shared hosting, I directly called
Tqdev\PhpCrudApi\ResponseUtils::output($this->responder->success(['results' => ":):)OK"]));
in my custom controler function
for example :
public function me(ServerRequestInterface $request): ResponseInterface
{
Tqdev\PhpCrudApi\ResponseUtils::output($this->responder->success(['results' => ":):)OK"]));
fastcgi_finish_request();
return $this->responder->success(['results' => 'OK']);
}
I still let the return to do (and so the second output in the main) but as the socket is close with fastcgi_finish_request(); I don't have any issue
@mevdschee : what do you think about it ?
I tried to add a test in the main to do only the output($response) if $response-> correctly defined but it seems to be a stream and not so easy to test..
Perhaps could we add a method in responder to disable the send of respond ?
Thanks
hello,
I've severall custom controllers ; each function/route create the Response return by api->handle and send as Response to the call.
I'd like to make post operations (after the response has been send) that can be time consuming like reindexing DB or making backup (few seconds) and I don't want to block the response..
Of course, I could add this function to the last line of the my api.php
`<?php
namespace Tqdev\PhpCrudApi;
use Tqdev\PhpCrudApi\Api;
use Tqdev\PhpCrudApi\Config\Config;
use Tqdev\PhpCrudApi\RequestFactory;
use Tqdev\PhpCrudApi\ResponseUtils;
require 'api.include.php';
require 'eCtrl.php';
require_once 'eConf.php';
$config = new Config([
'driver' => CONF_driver,
'address' => CONF_address,
'port' => CONF_port,
'database' => CONF_database,
'username' => CONF_username,
'password' => CONF_password,
'cachePath' => CONF_tempDir,
'cacheType'=>'TempFile',
'controllers'=>'cache', //"records,status', // for /status/ping
//'middlewares'=>'', // cors disabled xsrf don't work with cors disabled ?
'middlewares'=>'cors', // for dev only
'customControllers' => 'eCtrl',
]);
$request = RequestFactory::fromGlobals();
$api = new Api($config);
$response = $api->handle($request);
ResponseUtils::output($response);
file_put_contents('request.log',RequestUtils::toString($request)."===\n",FILE_APPEND);
file_put_contents('request.log',ResponseUtils::toString($response)."===\n",FILE_APPEND);
`
but in this case, how to call in this case a function of eCtrl class (not a static one?)
The text was updated successfully, but these errors were encountered: