Skip to content

Instantly share code, notes, and snippets.

View helgi's full-sized avatar

Helgi Þormar Þorbjörnsson helgi

View GitHub Profile
@helgi
helgi / gist:848296
Created February 28, 2011 23:46
A small function was experimenting with for the PEAR REST cache saving. It was open to link attacks (soft/hard links), attempting to take care of the time-of-check-time-of-use (TOCTOU) race condition as well as being able to create and/or update a cache f
<?php
function saveCacheFile($file, $contents)
{
$serialized = serialize($contents);
$len = strlen($serialized);
$cachefile_fp = @fopen($file, 'xb'); // x is the O_CREAT|O_EXCL mode
if ($cachefile_fp !== false) { // create file
if (fwrite($cachefile_fp, $serialized, $len) < $len) {
return PEAR::raiseError("Could not write $file.");
<?php
function saveCacheFile($file, $contents)
{
$len = strlen($contents);
$cachefile_fp = @fopen($file, 'xb'); // x is the O_CREAT|O_EXCL mode
if ($cachefile_fp !== false) { // create file
if (fwrite($cachefile_fp, $contents, $len) < $len) {
fclose($cachefile_fp);
return PEAR::raiseError("Could not write $file.");
@helgi
helgi / gist:1107620
Created July 26, 2011 19:03
Sample Pyrus_Dev
<?php
require_once __DIR__ . '/vendor/php/PEAR2/Autoload.php';
// Setup the local source dir
PEAR2\Autoload::initialize(__DIR__ . '/src');
// Setup the Pyrus_Developer checkout
PEAR2\Autoload::initialize(__DIR__ . '/../Pyrus/src');
// Fall back to the local vendor dir

Keybase proof

I hereby claim:

  • I am helgi on github.
  • I am helgi (https://keybase.io/helgi) on keybase.
  • I have a public key whose fingerprint is E2D3 707C 16EB 42A3 819D 176E A9BF 3A73 FB00 EE6A

To claim this, I am signing this object: