Created
November 6, 2012 16:52
-
-
Save meonkeys/4025975 to your computer and use it in GitHub Desktop.
Papertrail API repro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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