Skip to content

Instantly share code, notes, and snippets.

@vdbelt
vdbelt / cloudflare-purge-cache-service-worker.js
Created August 21, 2018 11:43
A CloudFlare service worker that proxies purge cache requests. Example: https://example.com/__purge_cache?zone=XX
addEventListener('fetch', event => {
event.respondWith(purgeCache(event.request))
})
async function purgeCache(request) {
const url = new URL(request.url)
@cp6
cp6 / bunnycdn_storage.php
Last active January 3, 2021 19:05
Bunny CDN Storage API format
<?php
header("Content-type:application/json");
function storage($key, $dir = '')
{
return json_decode(file_get_contents("https://storage.bunnycdn.com/" . $dir . "/?AccessKey=" . $key . ""), true);
}
$array = storage('STORAGE-PASSWORD-HERE', 'STORAGENAME');
$items = array('data' => array());
foreach ($array as $value) {
@jay7793
jay7793 / Instruction.sh
Last active August 4, 2023 08:01
Install Laravel 5.6 With PHP7.2 NGINX and PHP7.2-FPM on Ubuntu 16.04
# Install software-properties-common package to give us add-apt-repository package
sudo apt-get install -y software-properties-common
# Install latest nginx version from community maintained ppa
sudo add-apt-repository ppa:nginx/stable
# Update packages after adding ppa
sudo apt-get update
# Install nginx
@anthumchris
anthumchris / README.md
Last active September 25, 2022 19:04
Clear Nginx Cache

Clearing Nginx's HTTP Cache

I recently implemented Nginx HTTP content caching on our WordPress web servers to improve page load speeds and eliminate redundant, unneeded server-side page rendering. Caching the pages was relatively straightforward, but clearing the cache required a custom workaround.

Nginx comes in two versions: free and “Nginx Plus” at $2,500/year. The free version of Nginx does not offer the needed cache-clearing features of Nginx Plus, and I wasn’t comfortable paying $20,000 for 8 instances without trying to build my own solution.

Our Nginx servers run as an HTTP proxy for multiple PHP/MySQL-backed WordPress sites. The goal was to cache the dynamic PHP HTML responses in Nginx and serve the HTML pages from Nginx to avoid redundant, CPU-intensive PHP renders.

Site Cache Configuration

The example below shows how PHP response caching is configured for a site (other nginx configuration details are excluded for brevity). A cache named cachedemo-prod is defined to store cached HTML f

@selwynpolit
selwynpolit / read_csv.php
Last active February 14, 2024 16:56
Php code to read a csv file of any size without exhausting memory and let you process it in chunks
/*
Reads a CSV file in chunks of 10 lines at a time
and returns them in an array of objects for processing.
Assumes the first line of the CSV file has headings
that will be used as the object name for the item you are
processing. i.e. the heading is CurrentURL then refer to
$item->CurrentURL
@isuke01
isuke01 / custom-wp.ajax
Last active November 18, 2019 18:12
Custom WP ajax, capable of using SHORTINIT, and much faster than standard WP
<?php
/*
If you use short init by passing argument shortinit.
You have base and a bit more wp components loaded, like get_meta, current user .. etc.
*/
if (!isset( $_POST['action']))
die('-1');
if ( isset( $_POST['shortinit']) ){
$type = trim($_POST['shortinit']);
@rohankhudedev
rohankhudedev / opcache.ini
Last active April 19, 2024 09:56
Best Zend OpCache Settings / Tuning / Configurations
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=1
; The OPcache shared memory storage size.
opcache.memory_consumption=512
@viramgamijignesh
viramgamijignesh / Custom List Table With Database Example.php
Created January 18, 2018 09:19
Custom List Table With Database Example
<?php
/*
Plugin Name: Custom List Table With Database Example
Description: A highly documented plugin that demonstrates how to create custom admin list-tables from database using WP_List_Table class.
Version: 1.0
Author: Viramgami Jignesh
Author URI: https://github.com/viramgamijignesh/
License: GPL2
*/
@heiswayi
heiswayi / fm.php
Created October 25, 2017 14:00
Single PHP File Manager Script - Screenshot: https://i.imgur.com/4OtrKUz.png
<?php
/**
* File Manager Script
*/
// Default language ('en' and other from 'filemanager-l10n.php')
$lang = 'en';
// Auth with login/password (set true/false to enable/disable it)
$use_auth = true;
@hanshsieh
hanshsieh / VerifyIdToken.java
Last active June 10, 2020 00:22
Google Sign-in Example
import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken;
import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import java.util.Collections;
/**
* Hello world!