Skip to content

Instantly share code, notes, and snippets.

@rdlowrey
rdlowrey / pgsql-async.php
Last active January 16, 2020 17:14
Example usage of new non-blocking pgsql behavior
<?php
// Connect asynchronously (new constant for bitwise arg 2: PGSQL_CONNECT_ASYNC)
if (!$db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC)) {
echo "pg_connect() error\n";
} elseif (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
echo "pg_connect() error\n";
} elseif (!$stream = pg_socket($db)) {
echo "pg_socket() error\n";
}
@rdlowrey
rdlowrey / bench.js
Last active December 3, 2022 15:07
PHP vs Node.js scraping
/*
$ npm install request
$ node bench.js
*/
var request = require('request');
var url = 'http://www.google.com';
var total_requests = 100;
var i;
@rdlowrey
rdlowrey / uri-dot-segment-removal.php
Last active July 14, 2023 12:51
Remove dot segments from a URI path according to RFC3986 Section 5.2.4
<?php
/**
* Remove dot segments from a URI path according to RFC3986 Section 5.2.4
*
* @param $path
* @return string
* @link http://www.ietf.org/rfc/rfc3986.txt
*/
function removeDotPathSegments($path) {