-
Notifications
You must be signed in to change notification settings - Fork 101
Add an HTTP(S) driver #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davidstrauss
wants to merge
1
commit into
patrickallaert:master
Choose a base branch
from
pantheon-systems:https-driver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| APM stands for Alternative PHP Monitor | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2016 David Strauss | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: David Strauss <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <curl/curl.h> | ||
#include "php_apm.h" | ||
#include "php_ini.h" | ||
|
||
#include "driver_http.h" | ||
|
||
ZEND_EXTERN_MODULE_GLOBALS(apm) | ||
|
||
APM_DRIVER_CREATE(http) | ||
|
||
char *truncate_data(char *input_str, size_t max_len) | ||
{ | ||
char *truncated; | ||
input_str = input_str ? input_str : NULL; | ||
if (max_len == 0) | ||
return strdup(input_str); | ||
truncated = strndup(input_str, max_len); | ||
return truncated; | ||
} | ||
|
||
/* Insert an event in the backend */ | ||
void apm_driver_http_process_event(PROCESS_EVENT_ARGS) | ||
{ | ||
CURL *curl; | ||
CURLcode res; | ||
|
||
curl_global_init(CURL_GLOBAL_ALL); | ||
curl = curl_easy_init(); | ||
if(curl) { | ||
struct curl_httppost *formpost = NULL; | ||
struct curl_httppost *lastptr = NULL; | ||
struct curl_slist *headerlist = NULL; | ||
static const char buf[] = "Expect:"; | ||
char int2string[64]; | ||
char *trace_to_send; | ||
size_t max_len = 0; | ||
|
||
if (APM_G(http_max_backtrace_length) >= 0) | ||
max_len = APM_G(http_max_backtrace_length); | ||
|
||
trace_to_send = truncate_data(trace, max_len); | ||
|
||
sprintf(int2string, "%d", type); | ||
curl_formadd(&formpost, | ||
&lastptr, | ||
CURLFORM_COPYNAME, "type", | ||
CURLFORM_COPYCONTENTS, int2string, | ||
CURLFORM_END); | ||
|
||
curl_formadd(&formpost, | ||
&lastptr, | ||
CURLFORM_COPYNAME, "file", | ||
CURLFORM_COPYCONTENTS, error_filename ? error_filename : "", | ||
CURLFORM_END); | ||
|
||
sprintf(int2string, "%d", error_lineno); | ||
curl_formadd(&formpost, | ||
&lastptr, | ||
CURLFORM_COPYNAME, "line", | ||
CURLFORM_COPYCONTENTS, int2string, | ||
CURLFORM_END); | ||
|
||
curl_formadd(&formpost, | ||
&lastptr, | ||
CURLFORM_COPYNAME, "message", | ||
CURLFORM_COPYCONTENTS, msg ? msg : "", | ||
CURLFORM_END); | ||
|
||
curl_formadd(&formpost, | ||
&lastptr, | ||
CURLFORM_COPYNAME, "backtrace", | ||
CURLFORM_COPYCONTENTS, trace_to_send, | ||
CURLFORM_END); | ||
|
||
headerlist = curl_slist_append(headerlist, buf); | ||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); | ||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); | ||
|
||
curl_easy_setopt(curl, CURLOPT_URL, APM_G(http_server)); | ||
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, APM_G(http_request_timeout)); | ||
if (APM_G(http_client_certificate) != NULL) { | ||
curl_easy_setopt(curl, CURLOPT_SSLCERT, APM_G(http_client_certificate)); | ||
} | ||
if (APM_G(http_client_key) != NULL) { | ||
curl_easy_setopt(curl, CURLOPT_SSLKEY, APM_G(http_client_key)); | ||
} | ||
if (APM_G(http_certificate_authorities) != NULL) { | ||
curl_easy_setopt(curl, CURLOPT_CAINFO, APM_G(http_certificate_authorities)); | ||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L); | ||
} | ||
|
||
res = curl_easy_perform(curl); | ||
|
||
APM_DEBUG("[HTTP driver] Result: %s\n", curl_easy_strerror(res)); | ||
|
||
/* Always clean up. */ | ||
curl_easy_cleanup(curl); | ||
free(trace_to_send); | ||
} | ||
} | ||
|
||
int apm_driver_http_minit(int module_number) | ||
{ | ||
return SUCCESS; | ||
} | ||
|
||
int apm_driver_http_rinit() | ||
{ | ||
return SUCCESS; | ||
} | ||
|
||
int apm_driver_http_mshutdown() | ||
{ | ||
return SUCCESS; | ||
} | ||
|
||
int apm_driver_http_rshutdown() | ||
{ | ||
return SUCCESS; | ||
} | ||
|
||
void apm_driver_http_process_stats(TSRMLS_D) | ||
{ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| APM stands for Alternative PHP Monitor | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2016 David Strauss | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: David Strauss <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifndef DRIVER_HTTP_H | ||
#define DRIVER_HTTP_H | ||
|
||
#include "zend_API.h" | ||
|
||
#define APM_E_http APM_E_ALL | ||
|
||
apm_driver_entry * apm_driver_http_create(); | ||
|
||
PHP_INI_MH(OnUpdateAPMhttpErrorReporting); | ||
|
||
#endif |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the pattern would be to include
next = &(*next)->next;
with the HTTP driver, static analysis doesn't like assignment to an unused variable.