Skip to content

Instantly share code, notes, and snippets.

View adamziel's full-sized avatar
👋

Adam Zieliński adamziel

👋
View GitHub Profile
@adamziel
adamziel / 0. Running PHP processing logic after the request is over.md
Last active March 18, 2025 14:30
PHP – do work after the request is fully handled

Running PHP processing logic after the request is over

This is an experiment on running heavy processing logic after sending the response and finalizing the HTTP request processing. @dmsnell and I tried this as a part of the Site Transfer Protocol explorations.

Our idea was WordPress could process the request and then do some indexing in the remaining execution time. That would happen every n requests or every n seconds or somehow.

Async curl_exec()

@adamziel
adamziel / openAIPrompt.js
Last active March 16, 2025 16:26
openAIPrompt() function
// FileReader polyfill for environments that don't support it (like Node.js)
if (typeof FileReader === 'undefined') {
class FileReader {
constructor() {
this.onloadend = null;
}
readAsDataURL(blob) {
// For Node.js environments, we can use Buffer
if (typeof Buffer !== 'undefined' && blob.arrayBuffer) {
@adamziel
adamziel / mysql-protocol.ts
Last active March 14, 2025 01:19
Isomorphic MySQL connection handler – it may potentially be useful for SQLite support in WordPress Playground
import fs from 'fs';
import { createServer, Socket } from 'net';
import { createNodeFsMountHandler, getPHPLoaderModule } from '@php-wasm/node';
import { loadPHPRuntime, PHP } from '@php-wasm/universal';
import { bootWordPress } from '@wp-playground/wordpress';
const sqliteIntegrationPluginZip = fs.readFileSync(
'./sqlite-database-integration.zip'
);
const wordpressZip = fs.readFileSync('./wp-6.7.zip');
@adamziel
adamziel / 1. Commentary.md
Created January 8, 2025 19:59
WebSockets explorations

WebSockets in PHP

This is an experiment to run WebSockets in PHP without any extensions meant for WordPress Collaborative Editing.

Both approaches work, but both require custom hosting configuration. The first one – to proxy the traffic to a local WS server. The second one – to enable two-way data flow on the websockets route.

Requiring custom config is not ideal, but it could be a decent synchronization transport on some webhosts.

The preference cascade could go like:

<?php
/**
* Custom Gzip Decompressor.
*
* This is slower than all the PHP built-in gzip functions. The only
* advantage to using this class is that we can pause and resume decompression
* because we have access to the internal state.
*
* Usage example
*
127.0.0.1 - - 🕙 "GET /disable-http-cache HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET / HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/index-cae86eb4.js HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/index-ecfed2b2.css HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/modulepreload-polyfill-3cfb730f.js HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/preload-helper-cf010ec4.js HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/main-cb99c952.css HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/main-f66674a9.js HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/client-eb0b3bf7.js HTTP/1.1" 200 -
127.0.0.1 - - 🕙 "GET /assets/config-d962f5b8.js HTTP/1.1" 200 -
@adamziel
adamziel / package.json
Last active July 9, 2024 11:55
WordPress in Next.js app: Proof of Concept
{
"private": true,
"type": "module",
"scripts": {
"build": "next build",
"dev": "next dev",
"start": "next start"
},
"dependencies": {
"@php-wasm/node": "^0.9.18",
@adamziel
adamziel / sparse-checkout-in-js.js
Created June 21, 2024 00:21
JavaScript optimized Git client
// Run in a clone of isomorphic-git repo
import { GitPktLine } from './src/models/GitPktLine.js'
import { GitTree } from './src/models/GitTree.js'
import { GitAnnotatedTag } from './src/models/GitAnnotatedTag.js'
import { GitCommit } from './src/models/GitCommit.js'
import { GitPackIndex } from './src/models/GitPackIndex.js'
import { collect } from './src/internal-apis.js'
import { GitRemoteManager } from './src/managers/GitRemoteManager.js'
import { parseUploadPackResponse } from './src/wire/parseUploadPackResponse.js'
@adamziel
adamziel / Read page.js
Created June 18, 2024 10:46
Reag page using OpenAI API
async function fetchAudioBlob(textContent) {
const myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer TOKEN-HERE"); // Add your actual API key here
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({
"model": "tts-1",
"input": textContent,
"voice": "alloy"
});
@adamziel
adamziel / 1_usage.md
Created June 11, 2024 13:20
Markdown -> Blocks in Bun / Node.js

Converts markdown documents to WordPress block markup offline, without the browser.

Usage:

npm install
bun md-to-blocks.ts document.md > output.html