diff --git a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache index 70717056b9e..88954ffad3b 100644 --- a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache @@ -235,10 +235,25 @@ class APIClient { // Set user agent curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + // debugging for curl + if (Configuration::$debug) { + error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, Configuration::$debug_file); + + curl_setopt($curl, CURLOPT_VERBOSE, 1); + curl_setopt($curl, CURLOPT_STDERR, fopen(Configuration::$debug_file, 'a')); + } else { + curl_setopt($curl, CURLOPT_VERBOSE, 0); + } + // Make the request $response = curl_exec($curl); $response_info = curl_getinfo($curl); + // debug HTTP response body + if (Configuration::$debug) { + error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($response, true)."\n~END~\n", 3, Configuration::$debug_file); + } + // Handle the response if ($response_info['http_code'] == 0) { throw new APIClientException("TIMEOUT: api call to " . $url . diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 3eaa8dba1f1..5528e8076f3 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -34,6 +34,10 @@ class Configuration { // an instance of APIClient public static $apiClient; + // debugging + public static $debug = false; // by default debugging is disabled + public static $debug_file = 'php://output'; //output debug log to STDOUT by default + /* * manually initalize API client */ diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php index bc243e852cb..3e9119003d7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php @@ -245,12 +245,7 @@ class APIClient { error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, Configuration::$debug_file); curl_setopt($curl, CURLOPT_VERBOSE, 1); - try { - $fp = fopen(Configuration::$debug_file, 'w'); - curl_setopt($curl, CURLOPT_STDERR, $fp); - } catch ( \Exception $e ) { - error_log("Exception in enabling curl debug: ".print_r($e, true), 3, Configuration::$debug_file); - } + curl_setopt($curl, CURLOPT_STDERR, fopen(Configuration::$debug_file, 'a')); } else { curl_setopt($curl, CURLOPT_VERBOSE, 0); } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index 950b31ed587..fe4cbc59998 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -34,6 +34,7 @@ class Configuration { // an instance of APIClient public static $apiClient; + // debugging public static $debug = false; // by default debugging is disabled public static $debug_file = 'php://output'; //output debug log to STDOUT by default diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index 22bea9db889..4b63c75f472 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -8,6 +8,7 @@ require_once('SwaggerClient-php/SwaggerClient.php'); // to enable logging //SwaggerClient\Configuration::$debug = true; +//SwaggerClient\Configuration::$debug_file = '/var/tmp/php_debug.log'; $petId = 10005; // ID of pet that needs to be fetched try {