Skip to content

Commit 72d7d7e

Browse files
committed
add async handler
1 parent 967dc50 commit 72d7d7e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Understand\UnderstandLaravel\Handlers;
4+
5+
class AsyncHandler extends BaseHandler
6+
{
7+
8+
/**
9+
* Send data to storage
10+
*
11+
* @param string $requestData
12+
* @return void
13+
*/
14+
protected function send($requestData)
15+
{
16+
$parts = [
17+
'curl',
18+
'-X POST',
19+
'--cacert',
20+
$this->sslBundlePath,
21+
'-d',
22+
escapeshellarg($requestData),
23+
$this->getEndpoint(),
24+
'> /dev/null 2>&1 &'
25+
];
26+
27+
$cmd = implode(' ', $parts);
28+
29+
exec($cmd);
30+
}
31+
32+
/**
33+
* Serialize data and send to storage
34+
*
35+
* @param array $requestData
36+
* @return void
37+
*/
38+
public function handle(array $requestData)
39+
{
40+
$json = json_encode($requestData);
41+
42+
$this->send($json);
43+
}
44+
}

src/Understand/UnderstandLaravel/UnderstandLaravelServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ protected function resolveHandler($app)
144144
$handlerType = $app['config']->get('understand-laravel::config.handler');
145145
$sslBundlePath = $app['config']->get('understand-laravel::config.ssl_ca_bundle');
146146

147+
if ($handlerType == 'async')
148+
{
149+
return new Handlers\AsyncHandler($inputToken, $apiUrl, $silent, $sslBundlePath);
150+
}
151+
147152
if ($handlerType == 'sync')
148153
{
149154
return new Handlers\SyncHandler($inputToken, $apiUrl, $silent, $sslBundlePath);

0 commit comments

Comments
 (0)