Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/php-extension/RequestProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ bool RequestProcessor::Init() {
return true;
}

static std::string GetRuntimePhpVersion() {
zval* version = zend_get_constant_str(ZEND_STRL("PHP_VERSION"));
if (version && Z_TYPE_P(version) == IS_STRING) {
return Z_STRVAL_P(version);
}
return "";
}

std::string RequestProcessor::GetInitData(const std::string& userProvidedToken) {
LoadEnvironment();

Expand All @@ -91,7 +99,7 @@ std::string RequestProcessor::GetInitData(const std::string& userProvidedToken)
json initData = {
{"token", globalToken},
{"platform_name", AIKIDO_GLOBAL(sapi_name)},
{"platform_version", PHP_VERSION},
{"platform_version", GetRuntimePhpVersion()},
{"endpoint", AIKIDO_GLOBAL(endpoint)},
{"config_endpoint", AIKIDO_GLOBAL(config_endpoint)},
{"log_level", AIKIDO_GLOBAL(log_level_str)},
Expand Down
3 changes: 3 additions & 0 deletions tests/server/test_platform_version/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo PHP_VERSION;
10 changes: 10 additions & 0 deletions tests/server/test_platform_version/start_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"success": true,
"serviceId": 1,
"heartbeatIntervalInMS": 600000,
"endpoints": [],
"blockedUserIds": [],
"allowedIPAddresses": [],
"receivedAnyStats": false,
"block": false
}
17 changes: 17 additions & 0 deletions tests/server/test_platform_version/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from testlib import *

'''
1. Sends a request to a page that prints the PHP version of the running server.
2. Checks that the 'started' event reports that version, not the version of the PHP headers the extension was built against.
'''

def run_test():
response = php_server_get("/")
assert_response_code_is(response, 200)

events = mock_server_get_events()
assert_event_contains_subset("__root", events[0], {"type": "started", "agent": {"platform": {"version": response.text}}})

if __name__ == "__main__":
load_test_args()
run_test()
Loading