Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for Http request #3

Closed
yuskamal opened this issue Jul 19, 2020 · 5 comments
Closed

Wait for Http request #3

yuskamal opened this issue Jul 19, 2020 · 5 comments

Comments

@yuskamal
Copy link

how to wait/await http-request ?

@walkor
Copy link
Owner

walkor commented Jul 20, 2020

Sorry, http-client does not support wait/await.

@yuskamal
Copy link
Author

function getPartnerService($postnya)
{
global $http_req;
global $http_worker;

$url = $http_worker->hostconfig["url"].":".$http_worker->hostconfig["port"].$http_worker->hostconfig["endpoint"];
$auth = "Basic ".base64_encode($http_worker->hostconfig ["basic_auth_user"] . ":" . $http_worker->hostconfig ["basic_auth_pass"]);

$http_req->request($url,['method' => 'POST',
'headers' => ['Connection' => 'keep-alive',
'Authorization' => $auth,
'Content-type' => 'application/json'],
'data' => $postnya,
'success' => function ($response) {
$body = $response->getBody(); // ==> Return to Caller Function
}
},
'error' => function ($exception) {
echo $exception;
}
]);
}

It's possible return $response to caller function ?

@walkor
Copy link
Owner

walkor commented Jul 20, 2020

It's possible return $response to caller function ?

Sorry, http-client can't do this. I think you should use curl.

@yuskamal
Copy link
Author

OK thanks

@walkor walkor closed this as completed Jul 20, 2020
@eeliu
Copy link

eeliu commented Oct 16, 2020

@yuskamal
I met the same problem.
The only way can reach it is do the wait/await logic in 'success' and 'error' callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants