Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/root_span_for_PHP_lifecycle_re…
Browse files Browse the repository at this point in the history
…quest' into root_span_for_PHP_lifecycle_request
  • Loading branch information
SergeyKleyman committed May 28, 2024
2 parents dda5eac + 06152ba commit c9c2085
Show file tree
Hide file tree
Showing 31 changed files with 820 additions and 133 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ jobs:
prod/native/_build/${{ matrix.arch }}-release/extension/code/elastic_otel_php*.debug
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.so
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.debug
prod/native/_build/${{ matrix.arch }}-release/phpbridge_extension/code/phpbridge_*.so
prod/native/_build/${{ matrix.arch }}-release/phpbridge_extension/code/phpbridge_*.debug
8 changes: 8 additions & 0 deletions .github/workflows/test-phpt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ jobs:
done
popd
pushd prod/native/phpbridge_extension/phpt
for PHP_VERSION in "${PHP_VERSIONS[@]}"
do
./run.sh -b ${BUILD_ARCHITECTURE} -p ${PHP_VERSION} -f ${PWD}/results/phpt-bridge-${PHP_VERSION}.tar.gz || TEST_ERROR=1
done
popd
if [ $TEST_ERROR -eq 1 ]; then
echo "Some tests failed"
exit 1
Expand Down
1 change: 1 addition & 0 deletions prod/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ add_subdirectory(libcommon)
add_subdirectory(libphpbridge)
add_subdirectory(loader)
add_subdirectory(extension)
add_subdirectory(phpbridge_extension)
110 changes: 0 additions & 110 deletions prod/native/extension/code/tests_util/tests_util.php

This file was deleted.

24 changes: 1 addition & 23 deletions prod/native/libphpbridge/code/OpCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ bool PhpBridge::isOpcacheEnabled() const {


bool PhpBridge::detectOpcachePreload() const {

if (PHP_VERSION_ID < 70400) {
return false;
}

if (!isOpcacheEnabled()) {
return false;
}
Expand All @@ -33,24 +28,7 @@ bool PhpBridge::detectOpcachePreload() const {
return false;
}

return sapi_module.activate == nullptr && sapi_module.deactivate == nullptr && sapi_module.register_server_variables == nullptr && sapi_module.getenv == nullptr && EG(error_reporting) == 0;

// // lookup for opcache_get_status
// if (EG(function_table) && !zend_hash_str_find_ptr(EG(function_table), ZEND_STRL("opcache_get_status"))) {
// return false;
// }

// zval *server = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"));
// if (!server || Z_TYPE_P(server) != IS_ARRAY) {
// return true; // actually should be available in preload
// }

// // not available in preload request
// zval *script = zend_hash_str_find(Z_ARRVAL_P(server), ZEND_STRL("SCRIPT_NAME"));
// if (!script) {
// return true;
// }
return false;
return sapi_module.activate == nullptr && sapi_module.deactivate == nullptr && sapi_module.register_server_variables == nullptr && sapi_module.getenv == nullptr; // EG(error_reporting) == 0 is null only in request init scope
}


Expand Down
1 change: 1 addition & 0 deletions prod/native/libphpbridge/code/PhpBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ bool PhpBridge::callPHPSideErrorHandler(int type, std::string_view errorFilename
}


//NOTE: argument must be lower case
zend_class_entry *findClassEntry(std::string_view className) {
return static_cast<zend_class_entry *>(zend_hash_str_find_ptr(EG(class_table), className.data(), className.length()));
}
Expand Down
2 changes: 2 additions & 0 deletions prod/native/phpbridge_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

add_subdirectory(code)
93 changes: 93 additions & 0 deletions prod/native/phpbridge_extension/code/BridgeModuleEntry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "BridgeModuleGlobals.h"
#include "BridgeModuleFunctions.h"

#include "elastic_apm_version.h"


#include <main/php.h>
#include <Zend/zend_types.h>

ZEND_DECLARE_MODULE_GLOBALS(phpbridge);

#ifndef ZEND_PARSE_PARAMETERS_NONE
# define ZEND_PARSE_PARAMETERS_NONE() \
ZEND_PARSE_PARAMETERS_START(0, 0) \
ZEND_PARSE_PARAMETERS_END()
#endif

PHP_RINIT_FUNCTION(phpbridge) {
return SUCCESS;
}

PHP_RSHUTDOWN_FUNCTION(phpbridge) {
return SUCCESS;
}

ZEND_RESULT_CODE PhpBridgePostDeactivate(void) {
return ZEND_RESULT_CODE::SUCCESS;
}

PHP_MINFO_FUNCTION(phpbridge) {
}


PHP_GINIT_FUNCTION(phpbridge) {
phpbridge_globals->globals = new BridgeGlobals();
}

PHP_GSHUTDOWN_FUNCTION(phpbridge) {
delete phpbridge_globals->globals;
phpbridge_globals->globals = nullptr;
}

PHP_MINIT_FUNCTION(phpbridge) {
return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(phpbridge) {
return SUCCESS;
}

zend_module_entry phpbridge_module_entry = {
STANDARD_MODULE_HEADER,
"elastic_phpbridge", /* Extension name */
phpbridge_functions, /* zend_function_entry */
PHP_MINIT(phpbridge), /* PHP_MINIT - Module initialization */
PHP_MSHUTDOWN(phpbridge), /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(phpbridge), /* PHP_RINIT - Request initialization */
PHP_RSHUTDOWN(phpbridge), /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(phpbridge), /* PHP_MINFO - Module info */
PHP_ELASTIC_APM_VERSION, /* Version */
PHP_MODULE_GLOBALS(phpbridge), /* PHP_MODULE_GLOBALS */
PHP_GINIT(phpbridge), /* PHP_GINIT */
PHP_GSHUTDOWN(phpbridge), /* PHP_GSHUTDOWN */
PhpBridgePostDeactivate, /* post deactivate */
STANDARD_MODULE_PROPERTIES_EX
};

# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
extern "C" ZEND_GET_MODULE(phpbridge)
Loading

0 comments on commit c9c2085

Please sign in to comment.