Skip to content

Instantly share code, notes, and snippets.

💭
🌭

Jeremy Mikola jmikola

💭
🌭
Block or report user

Report or block jmikola

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jmikola
jmikola / README.md
Last active Oct 9, 2018
Testing the PHP driver with Atlas failovers
View README.md

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 Oct 4, 2017
PHPLIB mapReduce example
View example.php
<?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 Jun 16, 2017
Profiling MongoDB queries
View profiling.php
<?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 Dec 15, 2016
Benchmarking buffering via php://memory and raw strings
View MemoryStreamBench.php
<?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 Dec 5, 2016
Benchmark findAndModify with manual typeMap conversion
View benchmark.php
<?php
require 'vendor/autoload.php';
function createNestedDocuments($n, $depth)
{
$document = new stdClass;
if ($depth < 1) {
return $document;
@jmikola
jmikola / transcript.txt
Created Sep 12, 2015
Pacific Northwest PHP ReactPHP chat server
View transcript.txt
$ 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 Aug 29, 2015
Testing memory usage with MongoGridFS::storeFile()
View README.md

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.

@jmikola
jmikola / bench.log
Created May 25, 2015
Benchmarking PHP exception throws and backtrace generation
View bench.log
$ php bench.php
Throwing: 0.060640
Assigning and throwing: 0.064791
Assigning once and throwing: 0.011064
@jmikola
jmikola / transcript.txt
Last active Aug 29, 2015
Lone Star PHP ReactPHP chat server
View transcript.txt
Script started on Sat 18 Apr 2015 01:41:51 PM CDT
$ telnet jmikola.net 8888
Trying 97.107.131.54...
Connected to jmikola.net.
Escape character is '^]'.
Hello.
24.173.35.158: Hi!
24.173.35.158: GET / HTTP/1.1
Host: jmikola.net:8888
Connection: keep-alive
@jmikola
jmikola / PedantryTest.php
Created Mar 18, 2015
Pedantic tests that have nothing to do with functional correctness
View PedantryTest.php
<?php
namespace MongoDB\Tests;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionClass;
use ReflectionMethod;
use RegexIterator;
You can’t perform that action at this time.