Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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)