Skip to content

Instantly share code, notes, and snippets.

View saleemkce's full-sized avatar

Saleem Khan saleemkce

  • formerly at Pearson PLC & Ranbas Software
  • Chennai, India
View GitHub Profile
@scarf005
scarf005 / pre-commit
Last active November 25, 2022 07:08
forbid committing to default branch directly
#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)
default=$(basename $(git rev-parse --abbrev-ref origin/HEAD))
lang=$(locale | head -n 1 | cut -d'=' -f2 | cut -d'.' -f1)
if [ "$branch" != "$default" ]; then
exit 0
fi
@eridal
eridal / Compiler.java
Last active August 9, 2023 13:26
Java to PHP Compilation
package j2p;
import japa.parser.JavaParser;
import japa.parser.ParseException;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.ImportDeclaration;
import japa.parser.ast.PackageDeclaration;
import japa.parser.ast.body.BodyDeclaration;
import japa.parser.ast.body.ClassOrInterfaceDeclaration;
import japa.parser.ast.body.FieldDeclaration;
<?php
/**
* Test running a console command in threads (PHP pthread extension) vs loop vs &&
*/
class WorkerThreads extends Thread
{
private $workerId;
public $data;
@krakjoe
krakjoe / pool.md
Last active January 30, 2020 12:33
Pooling

Easy pthreads Pools

The final solution !!

Since the first version of pthreads, PHP has had the ability to initialize Worker threads for users. Onto those Worker threads are stacked objects of class Stackable for execution concurrently.

The objects stacked onto workers do not have their reference counts changed, pthreads forces the user to maintain the reference counts in userland, for the extremely good reason that this enables the programmer to keep control of memory usage; and so, execute indefinitely.

This is the cause of much heartache for newcomers to pthreads; if you do not maintain references properly you will, definitely, experience segmentation faults.

@saleemkce
saleemkce / multi-execute-PHP.php
Last active January 3, 2016 05:50
Execute multiple SQL statements in PHP for Mysql database.
<?php
/*
Execute multiple SQL statements in PHP or directly execute .SQL files in MySql using PHP
*/
ini_set('display_errors', 0);
error_reporting(0);
// SET MYSQL CONFIGURATION
$serverName = 'localhost';
$username = 'root';
$password = '';
@krakjoe
krakjoe / pthreads.md
Last active September 24, 2024 14:50
pthreads.md

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls