lundi 19 février 2024

Switch from PHP 7.4 to PHP 8.3

sudo dpkg -l | grep php | tee packages.txt
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3 php8.3-cli php8.3-{bz2,curl,mbstring,intl}
sudo apt install php8.3-fpm
sudo a2enconf php8.3-fpm
sudo a2disconf php7.4-fpm

mercredi 17 janvier 2024

Working with Cassandra in native PHP

When working with Cassandra in native PHP, you'll typically use a driver like php-cassandra to interact with the Cassandra database. Here's a basic example of how you can ensure data replication using native PHP:

1. Install php-cassandra:

composer require datastax/php-driver

2. Establish Connection and Configure Replication:

<?php
// Load the Composer autoloader require_once 'vendor/autoload.php'; // Cassandra connection configuration $cluster = Cassandra::cluster()->build(); $session = $cluster->connect(); // Keyspace configuration with replication $keyspace = 'your_keyspace'; $replicationFactor = 2; // Adjust according to your requirements // Create keyspace with replication strategy $query = sprintf( "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': %d}", $keyspace, $replicationFactor ); $session->execute(new Cassandra\SimpleStatement($query)); // Set the keyspace for further queries $session->execute(new Cassandra\SimpleStatement("USE $keyspace")); // Example: Create a table (replace with your table structure) $tableQuery = " CREATE TABLE IF NOT EXISTS your_table ( id UUID PRIMARY KEY, name VARCHAR ) "; $session->execute(new Cassandra\SimpleStatement($tableQuery)); // Example: Insert data (replace with your data) $insertQuery = " INSERT INTO your_table (id, name) VALUES (uuid(), 'John Doe') "; $session->execute(new Cassandra\SimpleStatement($insertQuery)); // Close the connection $cluster->shutdown();

3. Testing Replication:

  1. Check the Cassandra cluster status using the nodetool command in the Cassandra installation directory:

    nodetool status

    Ensure all nodes are up and running.

  2. Monitor replication using nodetool:

    nodetool describecluster

    Verify that the replication factor matches the configuration.

Note: The above code is a basic example. You should replace your_keyspace and your_table with your actual keyspace and table names. Additionally, handle exceptions and errors appropriately in a production environment.

This is a basic example, and for a more comprehensive solution, consider using a framework or library like Symfony with Doctrine when working with databases in PHP projects. These tools provide abstractions and features that simplify database interactions and replication handling.

vendredi 18 septembre 2020

Since symfony/dependency-injection 5.1: The "Symfony\Component\DependencyInjection\ContainerInterface" autowiring alias is deprecated. [FIXED] [RESOLVED]

 May be a lot of you, have seen this deprecation message while the migration to symfony 5.1.
So here the solution:

Symfony is really discouraging the injection of the global container. To fix the message, all you need to do is to explicitly define the ContainerInterface alias as the Symfony Profiler recommanded you:

# services.yml or yaml
services:
    Symfony\Component\DependencyInjection\ContainerInterface: '@service_container'

mercredi 4 décembre 2019

Symfony : Making your Code Follow the Coding Standards

First download the phar file: here
then copy the file in your project racine.
now all to do is to execute the phar file considering the code directory (in my case: 'src'):

cd your-project/
php php-cs-fixer-v2.phar fix -v src

vendredi 28 juin 2019

.htaccess https no www

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

mardi 5 mars 2019

Ubuntu / Debian: Low Level Formatting

To retrieve the code name (that is, the xxx of / dev / xxx) from your hard disk, do:

sudo fdisk -l

You will see the list of hard drives and their partitions ... Take for example the hard disk / dev / sda, which you want to format.
dd if=/dev/zero of=/dev/sda