com web/qa: Add simple request logging for debugging purpose: pulls/api.php
| From: | Johannes Schlüter | Date: | Fri, 23 Mar 2012 23:02:17 +0000 |
| Subject: | com web/qa: Add simple request logging for debugging purpose: pulls/api.php | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66172@lists.php.net to get a copy of this message | ||
Commit: 5e4a747cc01933b3ab5cb4868d38bd0793d08529
Author: Johannes Schlüter <johannes@php.net> Sat, 24 Mar 2012 00:02:17 +0100
Parents: f90ab6e177999b70ceca6b838f881c18af73226e
Branches: master
Link: http://git.php.net/?p=web/qa.git;a=commitdiff;h=5e4a747cc01933b3ab5cb4868d38bd0793d08529
Log:
Add simple request logging for debugging purpose
After calling api.php?action=requestlog once all requests are logged to
the current PHP session. Subsequent requests to the requestlog will dump
the information.
Changed paths:
M pulls/api.php
Diff:
5e4a747cc01933b3ab5cb4868d38bd0793d08529
diff --git a/pulls/api.php b/pulls/api.php
index 9c1700a..9174675 100644
--- a/pulls/api.php
+++ b/pulls/api.php
@@ -52,15 +52,27 @@ function verify_password_DEV($user, $pass)
return $user === 'johannes';
}
-function do_http_request($url, $ctxt)
+function do_http_request($url, $opts)
{
global $errors;
+ $ctxt = stream_context_create(array('http' => $opts));
+ $actual_url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@',
$url);
+
$old_track_errors = ini_get('track_errors');
ini_set('track_errors', true);
- $s = @file_get_contents($url, false, $ctx);
+ $s = @file_get_contents($actual_url, false, $ctx);
ini_set('track_errors', $old_track_errors);
+ if (isset($_SESSION['debug']['requests'])) {
+ $_SESSION['debug']['requests'][] = array(
+ 'url' => $url,
+ 'opts'=> $opts,
+ 'headers' => $http_response_header,
+ 'response' => $s
+ );
+ }
+
if (!$s) {
$errors[] = "Server responded: ".$http_response_header[0];
$errors[] = "Github user: ".GITHUB_USER;
@@ -87,10 +99,7 @@ function ghpostcomment($pull, $comment)
'content' => $post,
);
- $ctx = stream_context_create(array('http' => $opts));
-
- $url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@',
$pull->_links->comments->href);
- return (bool)do_http_request($url, $ctx);
+ return (bool)do_http_request($pull->_links->comments->href, $opts);
}
function ghchangestate($pull, $state)
@@ -102,10 +111,7 @@ function ghchangestate($pull, $state)
'content' => $content
);
- $ctx = stream_context_create(array('http' => $opts));
-
- $url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@',
$pull->_links->self->href);
- return (bool)do_http_request($url, $ctx);
+ return (bool)do_http_request($pull->_links->self->href, $opts);
}
function login()
@@ -195,6 +201,16 @@ function ghupdate()
die(json_encode(array('success' => true)));
}
+function requestlog() {
+ if (!isset($_SESSION['debug']['requests'])) {
+ $_SESSION['debug']['requests'] = array();
+ }
+
+ header('Content-Type: text/plain');
+ var_dump($_SESSION['debug']['requests']);
+ exit;
+}
+
header('Content-Type: application/json');
session_start();
@@ -202,7 +218,8 @@ $accepted_actions = array(
'login',
'logout',
'loggedin',
- 'ghupdate'
+ 'ghupdate',
+ 'requestlog'
);
if (isset($_REQUEST['action']) && in_array($_REQUEST['action'],
$accepted_actions)) {
$action = $_REQUEST['action'];