Skip to content

Instantly share code, notes, and snippets.

@meonkeys
Created November 6, 2012 16:52
Show Gist options
  • Select an option

  • Save meonkeys/4025975 to your computer and use it in GitHub Desktop.

Select an option

Save meonkeys/4025975 to your computer and use it in GitHub Desktop.
Papertrail API repro
<?php
// Demonstrate Papertrail API issue. This stopped working 2012-11-05.
// workaround: create a new curl handle before every request
$ch = curl_init();
// First request. Output ignored.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Papertrail-Token: ' . $argv[1]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
//curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); // doesn't help
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_URL, 'https://papertrailapp.com/api/v1/systems.json');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
$content = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode !== 200) {
throw new \Exception("Error. Status=$statusCode. Message: " . $content);
}
// Second request. Exception thrown after 1 min or so timeout.
// Curl verbose output includes:
// * SSL re-using session ID
// * Unknown SSL protocol error in connection to papertrailapp.com:443
curl_setopt($ch, CURLOPT_URL, 'https://papertrailapp.com/api/v1/systems/REDACTED');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$data = array('system[name]' => 'REDACTED');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$content2 = curl_exec($ch);
$statusCode2 = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode2 !== 200) {
throw new \Exception("Error. Status=$statusCode2. Message: " . $content2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment