Learn from your fellow PHP developers with our PHP blogs, or help share the knowledge you've gained by writing your own.
prometheus/client_php
and php-prometheus/client
./metrics
) where Prometheus can scrape the metrics using the Prometheus exposition format.prometheus.yml
) to include the target endpoint and define any additional scraping parameters.prometheus/client_php
library:require 'vendor/autoload.php';
use Prometheus\CollectorRegistry;
use Prometheus\Storage\APC;
use Prometheus\RenderTextFormat;
$registry = new CollectorRegistry(new APC());
$requestDuration = $registry->registerCounter('php_requests_total', 'Total number of PHP requests');
$requestDuration->inc();
$renderer = new RenderTextFormat();
echo $renderer->render($registry->getMetricFamilySamples());
php_requests_total
) to track the total number of PHP requests. We then increment this metric for each request and expose the metrics endpoint using the Prometheus exposition format.class CreateProductCommand {
public $name;
public $price;
}
class GetProductQuery {
public $productId;
}
class CreateProductCommandHandler {
public function handle(CreateProductCommand $command) {
}
}
class GetProductQueryHandler {
public function handle(GetProductQuery $query) {
}
}
class Product {
public $name;
public $price;
}
class ProductView {
public $name;
public $price;
}
$command = new CreateProductCommand();
$command->name = "Example Product";
$command->price = 99.99;
$handler = new CreateProductCommandHandler();
$handler->handle($command);
$query = new GetProductQuery();
$query->productId = 123;
$handler = new GetProductQueryHandler();
$product = $handler->handle($query);
Ctrl + Alt + T
to open the terminal.Alt + F2
, type konsole
, and press Enter.cd
(Change Directory): Use cd
followed by the name of the directory to navigate to that directory. For example: cd Documents
ls
(List Files): Use ls
to list the files and directories in the current directory. ls
pwd
(Print Working Directory): Use pwd
to display the full path of the current directory. pwd
mkdir
(Make Directory): Use mkdir
followed by the name of the directory to create a new directory. mkdir my_directory
touch
: Use touch
followed by the name of the file to create a new empty file. touch my_file.txt
cp
(Copy): Use cp
followed by the source file and destination to copy files. cp source_file.txt destination_directory/
mv
(Move/Rename): Use mv
followed by the source and destination to move or rename files. mv old_name.txt new_name.txt
rm
(Remove): Use rm
followed by the file name to delete files. Be careful as this action is irreversible. rm unwanted_file.txt
cat
(Concatenate): Use cat
followed by the file name to display the contents of a file. cat my_file.txt
nano
or vim
(Text Editors): Use nano
or vim
followed by the file name to edit a file in the terminal. nano my_file.txt
grep
(Global Regular Expression Print): Use grep
followed by a search term and file name to search for a specific pattern in a file. grep "pattern" my_file.txt
uname
(Unix Name): Use uname
to display system information. uname -a
df
(Disk Free): Use df
to display disk space usage. df -h
top
or htop
(Process Monitoring): Use top
or htop
to display real-time system resource usage. top
composer require --dev phpunit/phpunit
tests
in your project root, and within that directory, create a file named ExampleTest.php
. Here's an example of what your test file might look like:<?php
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public function testTrueAssertsToTrue()
{
$this->assertTrue(true);
}
}
testTrueAssertsToTrue
, which asserts that true
is indeed true
. vendor/bin/phpunit tests
sudo apt-get install mariadb-server
.CREATE DATABASE my_database;
USE my_database;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL
);
my_database
and a table named users
with columns for id
, username
, and email
.INSERT INTO users (username, email) VALUES ('john_doe', '[email protected]');
SELECT * FROM users;
UPDATE users SET email = '[email protected]' WHERE username = 'john_doe';
DELETE FROM users WHERE username = 'john_doe';