Skip to content

Instantly share code, notes, and snippets.

@FerraBraiZ
FerraBraiZ / php_fpm_max_children.sh
Created November 5, 2024 17:03
php_fpm_max_children.sh
#!/bin/bash
# Get memory usage per child process
memory_usage_per_child=$(ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d\n", sum/NR/1024) }');
echo
echo "Average memory usage per child: ${memory_usage_per_child}MB"
# Get total available memory
total_available_memory=$(free -m | awk 'NR==2{print $2}');
total_available_memory_gb=$(echo "scale=2; $total_available_memory / 1024" | bc)
@FerraBraiZ
FerraBraiZ / POC - Jquery pinch-to-zoom-picture
Last active March 10, 2024 14:11
POC - Jquery pinch-to-zoom-picture
<!doctype html>
<html lang="pt-br">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
@FerraBraiZ
FerraBraiZ / siege
Created May 4, 2022 20:30 — forked from MikeNGarrett/siege
Siege with JSON POST data
# Changed to use content-type flag instead of header: -H 'Content-Type: application/json'
siege -c50 -t60S --content-type "application/json" 'http://domain.com/path/to/json.php POST {"ids": ["1","2","3"]}'
@FerraBraiZ
FerraBraiZ / creating-phar-files
Last active March 23, 2024 16:08
Creating Phar Files
Author: https://blog.programster.org/creating-phar-files
I write lots of helper scripts to do everyday tasks on my computer. These usually start out as BASH scripts, but quite often turn into PHP scripts/tools as they get more complex. For example, I use a PHP CLI tool for a personal password manager.
Sometimes a script turn into a "tool" that requires a couple of classes, so I stick them into a folder and have an external BASH script in my $PATH that calls the folders "entrypoint". However, wouldn't it be great if I could just package up the entire folder into a single executable file, much like Java's JAR. This is where the PHAR comes in.
If you use PHP you probably use a phar file every day in the form of composer. I had never bothered to learn how to create these files before because I assumed it would be hard, but it's actually easier than I could have believed.
Steps
Simply create a folder for your project, before creating a folder within there called "app" for your application's source code.
@FerraBraiZ
FerraBraiZ / git_maintenance_commands.sh
Last active March 23, 2024 12:50 — forked from Zoramite/maintenance.sh
Git Maintenance Commands
#!/bin/bash -xe
# Verifies the connectivity and validity of the objects in the database
git fsck --full
# Manage reflog information
git reflog expire --expire=now --all
# Pack unpacked objects in a repository
git repack -a -d -l
@FerraBraiZ
FerraBraiZ / Why Your Dockerized Application Isn’t Receiving Signals.txt
Last active March 23, 2024 12:57
Why Your Dockerized Application Isn’t Receiving Signals
An Article by Hynek Schlawack all credits goes to him!
https://hynek.me/articles/docker-signals/
Why Your Dockerized Application Isn’t Receiving Signals - 19 June 2017
Proper cleanup when terminating your application isn’t less important when it’s running inside of a Docker container.
Although it only comes down to making sure signals reach your application and handling them, there’s a bunch of
things that can go wrong.
In principle it’s really simple: when you – or your cluster management tool – run docker stop, Docker sends a
~$ cat /etc/nginx/conf.d/default.conf
server {
listen 80;
listen [::]:80;
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
server_name _;
root /var/www;
index /index.php;
@FerraBraiZ
FerraBraiZ / PHP-Handle-Signals.php
Last active March 23, 2024 16:10 — forked from pcdinh/process1.php
PHP Handle Signals
<?php
declare(ticks = 1);
function handleExit($signal)
{
error_log("Caught a $signal signal, a worker process exiting\n", 3, './error-child-log');
exit(1);
}
pcntl_signal(SIGTERM, 'handleExit');

Terraform Certification Revision

1 Understand Infrastructure as Code (IaC) concepts

Terraform by default provision concurrently 10 resources, to change use -parallelism=n on plan, apply and destroy commands.

Terraform is an immutable, declarative, Infraestructure as Code provisioning tool.

IaC provides benefits:

  • Can be versioned
@FerraBraiZ
FerraBraiZ / PHP Headers allow CORS.php
Created April 9, 2021 17:34
PHP Headers allow CORS
<?php
/* set the HTTP_ORIGIN to the requester origin if empty */
if( isset( $_SERVER['HTTP_ORIGIN'] ) && $_SERVER['HTTP_ORIGIN'] != '' )
{
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 0'); // cache for 0 day