PHP code example of cosmastech / laravel-statsd-adapter
1. Go to this page and download the library: Download cosmastech/laravel-statsd-adapter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cosmastech / laravel-statsd-adapter example snippets
use Cosmastech\LaravelStatsDAdapter\Stats;
// Increment a counter
Stats::increment('page.views');
// Record a gauge
Stats::gauge('user.login', 1);
// Record a timing (in ms)
Stats::timing('response.time', 320);
use Cosmastech\StatsDClientAdapter\Adapters\StatsDClientAdapter;
use App\Models\User;
use App\Models\Post;
class DeleteAllUserPostsAction
{
public function __construct(private readonly StatsDClientAdapter $statsClient)
{
}
public function __invoke(User $user): void
{
$user->posts->each(function(Post $post) use ($user) {
$post->delete();
$this->statsClient->decrement("posts", 1.0, ["user_id" => $user->id], 1);
});
}
}