Skip to content

Instantly share code, notes, and snippets.

@AllenJB
AllenJB / jenkins.md
Last active December 21, 2022 11:31
Jenkins & PHP

Jenkins & PHP

This is a guide to setting up Jenkins for PHP projects. The Jenkins plugins required are linked in each section below.

Be sure to check the pipeline step reference link on the plugin pages linked below for full documentation and options for Jenkinsfile.

This guide uses Jenkinsfile based pipelines and assumes you already have a basic Jenkinsfile.

This guide assumes that you already have each of the tools mentioned configured for use outside of Jenkins. Only the necessary configuration options for working with Jenkins are mentioned.

@AllenJB
AllenJB / oom_example.php
Created December 3, 2022 10:35
PHP: Change memory_limit in shutdown handler after OOM
<?php
ini_set('memory_limit', '2M');
function shutdownHandler()
{
print "Shutdown handler triggered\n";
print "Memory limit: ". ini_get('memory_limit') ."\n";
// If the next line is commented, a second OOM will be triggered
ini_set('memory_limit', '-1');
print "Memory limit: ". ini_get('memory_limit') ."\n";
@AllenJB
AllenJB / DateTimeFactory.php
Created September 23, 2022 18:08
PHP DateTimeFactory
<?php
class DateTimeFactory
{
public static function createImmutableFromFormat(string $format, string $time, \DateTimeZone $timezone = null) : \DateTimeImmutable
{
$dt = \DateTimeImmutable::createFromFormat($format, $time, $timezone);
// DateTime errors/warnings can occur even if the object was successfully created (eg. invalid date)
@AllenJB
AllenJB / stylus.css
Last active August 1, 2020 13:44
June 2020 GitHub Redesign Modifications
.IssueLabel {
border-radius: 3px !important;
padding: 0 3px !important;
}
.UnderlineNav {
justify-content: center;
}
.UnderlineNav-item {
@AllenJB
AllenJB / gist:fd2fdea2ff3cbab7cbf74463f0650994
Created February 14, 2020 08:55
PHP Intentional Error Tests
public function fatalMemory() : void
{
$a = '';
while (true) {
$a .= str_repeat("Hello", 1024 * 1024);
}
}
public function timeout() : void
@AllenJB
AllenJB / _wishlist.md
Last active December 7, 2023 14:37
PHP Wishlist
@AllenJB
AllenJB / phpfpm-prometheus.php
Created July 12, 2019 19:50
PHP-FPM Pool Monitoring w/ Prometheus
<?php
declare(strict_types=1);
// Prometheus metrics exporter for PHP-FPM
header("Content-Type: text/plain; version=0.0.4");
$stats = null;
$protocol = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] !== "off") ? "https" : "http");
$result = file_get_contents($protocol ."://" . $_SERVER["SERVER_NAME"] . "/php-fpm-status?json&full");
if ($result !== false) {
@AllenJB
AllenJB / array_merge vs plus.php
Created March 25, 2019 09:07
PHP Canonical Answers & Stuff
<?php
// https://3v4l.org/e79nG
$arr1 = [1, 2, 3];
$arr2 = [2, 4, 1];
$arr1 += $arr2;
var_dump($arr1);
$arr1 = ["foo", "bar", "baz"];
@AllenJB
AllenJB / async-worker-cancel.php
Last active July 6, 2018 11:55
Bunny Async Worker w/ signal handler
<?php
use Bunny\Channel;
use Bunny\Async\Client;
use Bunny\Message;
use Bunny\Protocol\MethodBasicConsumeOkFrame;
use React\EventLoop\Factory;
require '../../vendor/autoload.php';
@AllenJB
AllenJB / gist:872553b5cb2086b0b8de9b0c50044ce5
Last active June 30, 2018 17:47
MySQL join same table on different fields
SELECT table1.employee_id_1, table1.employee_id_2, e1.first_name AS e1_first_name, e2.first_name AS e2_first_name
FROM table1
LEFT JOIN employee_tbl AS e1 ON table1.employee_id_1 = e1.employee_id
LEFT JOIN employee_tbl AS e2 ON table2.employee_id_2 = e2.employee_id