Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jmikola's full-sized avatar
💭
🌭

Jeremy Mikola jmikola

💭
🌭
View GitHub Profile
@jmikola
jmikola / README.md
Last active February 3, 2023 18:58
Using gallery-dl to backup a Twitter account
@jmikola
jmikola / output.log
Created November 3, 2022 08:25
Change tracking using ext-mongodb's BSON API
$ php tracked_persistable.php
object(MongoDB\Examples\User)#29 (3) {
["name"]=>
string(7) "alcaeus"
["emails"]=>
object(MongoDB\Examples\TrackedBSONArray)#24 (0) {
}
["_id"]=>
object(MongoDB\BSON\ObjectId)#15 (1) {
["oid"]=>
<?php
enum TimeUnit : string
{
case Nanos = 'ns';
case Micros = 'μs';
case Millis = 'ms';
}
class TimeUnitString
@jmikola
jmikola / README.md
Last active June 24, 2022 15:58
Testing the PHP driver with Atlas failovers

Testing the PHP driver with Atlas failovers

Ping

The following was added to the URI for an Atlas 3.6 cluster and assigned to a $uri variable in the PHP script:

?serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000
@jmikola
jmikola / example.php
Created October 4, 2017 16:22
PHPLIB mapReduce example
<?php
require_once 'vendor/autoload.php';
$client = new MongoDB\Client;
$collection = $client->selectCollection('test', 'mr_example');
$collection->drop();
$collection->insertMany([
['x' => 1, 'y' => 1],
@jmikola
jmikola / profiling.php
Created June 16, 2017 15:45
Profiling MongoDB queries
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client();
$db = $client->selectDatabase('test');
// Disable profiling before dropping system.profile
$db->command(['profile' => 0]);
@jmikola
jmikola / MemoryStreamBench.php
Created December 15, 2016 20:35
Benchmarking buffering via php://memory and raw strings
<?php
// composer require phpbench/phpbench @dev --dev
// vendor/bin/phpbench run MemoryStreamBench.php --report='generator: "table", compare: "revs", cols: ["subject", "mean"]'
/**
* @Revs(1000)
* @Iterations(5)
*/
class MemoryStreamBench
@jmikola
jmikola / benchmark.php
Created December 5, 2016 14:58
Benchmark findAndModify with manual typeMap conversion
<?php
require 'vendor/autoload.php';
function createNestedDocuments($n, $depth)
{
$document = new stdClass;
if ($depth < 1) {
return $document;
@jmikola
jmikola / transcript.txt
Created September 12, 2015 22:37
Pacific Northwest PHP ReactPHP chat server
$ telnet jmikola.net 8888
Trying 97.107.131.54...
Connected to jmikola.net.
Escape character is '^]'.
Hi!
208.79.146.242: Hello!
208.79.146.242: yo
208.79.146.242: hello
208.79.146.242: YO
208.79.146.242: Bonjour
@jmikola
jmikola / README.md
Last active August 29, 2015 14:23
Testing memory usage with MongoGridFS::storeFile()

Configuration

For our tests, we used random input data created cat /dev/urandom > random.txt.

Set the URI, database, and GridFS collection names accordingly. Additionally, decide if the GridFS collection should be dropped before inserting any data.

The number of iterations can be customized. Based on the results, there were modest increases to peak memory on successive iterations. Real memory usage tended to drop with each new iteration and climb again.

By default, the driver uses a chunk size of 255 * 1024 (i.e. 255K). This default seems to leak memory (at least until the file insert completes). Increasing the chunk size even just a bit 256K has vastly better results.