Skip to content

Commit

Permalink
[Replicate] compatibility with PHP 5.x (#97)
Browse files Browse the repository at this point in the history
original: #96

- Make sure run the test... Run the test for php5.5
- Add readme section about the mismatch of libcrypto from php and awscrt. 

---------

Co-authored-by: Remi Collet <remi@remirepo.net>
  • Loading branch information
TingDaoK and remicollet committed Mar 24, 2023
1 parent ed3f8ca commit 1926277
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ jobs:
run: |
phpize
./configure
make
- name: Install dependencies
# get path to composer.phar so we can run it with custom php.ini
run: |
COMPOSER_PHAR=$(realpath $(which composer))
php -c php.ini $COMPOSER_PHAR update --no-interaction
# Normally, CRT uses the system's default libcrypto.so.
# But in this CI run, PHP 5.5 is using a different older libcrypto.so, as PHP 5.5 cannot build with openssl >=1.1.1.
# When an applications uses two different libcrypto.so at the same time, things tend to explode.
# Therefore, in this CI run we build AWS-LC statically, and use its libcrypto.a instead.
USE_OPENSSL=OFF make
./dev-scripts/run_tests.sh
php-linux-x64:
runs-on: ubuntu-latest
Expand Down
11 changes: 11 additions & 0 deletions Makefile.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ ifneq (OFF,$(USE_OPENSSL))
ifneq (ON,$(USE_OPENSSL))
CMAKE_PREFIX_PATH=-DCMAKE_PREFIX_PATH=$(USE_OPENSSL)
endif
else
# Hide symbols from libcrypto.a
# This avoids problems when an application ends up using both libcrypto.a and libcrypto.so.
#
# An example of this happening is the aws-c-io tests.
# All the C libs are compiled statically, but then a PKCS#11 library is
# loaded at runtime which happens to use libcrypto.so from OpenSSL.
# If the symbols from libcrypto.a aren't hidden, then SOME function calls use the libcrypto.a implementation
# and SOME function calls use the libcrypto.so implementation, and this mismatch leads to weird crashes.
EXTRA_LDFLAGS="-Wl,--exclude-libs,libcrypto.a"
endif


CMAKE_CONFIGURE = $(CMAKE) \
-DCMAKE_SOURCE_DIR=$(srcdir) \
-DCMAKE_BINARY_DIR=$(CMAKE_BUILD_DIR) \
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# AWS Common Runtime PHP bindings

## Requirements

* PHP 5.5+ on UNIX platforms, 7.2+ on Windows
* CMake 3.x
* GCC 4.4+, clang 3.8+ on UNIX, Visual Studio build tools on Windows
Expand All @@ -17,7 +18,7 @@ pecl install awscrt
composer require aws/aws-crt-php
```

On Windows, you need to build from source as instruction written below for the native extension `php_awscrt.dll`. And, follow https://www.php.net/manual/en/install.pecl.windows.php#install.pecl.windows.loading to load extension. After that:
On Windows, you need to build from source as instruction written below for the native extension `php_awscrt.dll` . And, follow https://www.php.net/manual/en/install.pecl.windows.php#install.pecl.windows.loading to load extension. After that:

```
composer require aws/aws-crt-php
Expand Down Expand Up @@ -46,7 +47,7 @@ $ ./dev-scripts/run_tests.sh

From Command Prompt (not powershell). The instruction is based on Visual Studio 2019 on 64bit Windows.

``` bat
```bat
> git clone --recursive https://github.com/awslabs/aws-crt-php.git
> git clone https://github.com/microsoft/php-sdk-binary-tools.git C:\php-sdk
> C:\php-sdk\phpsdk-vs16-x64.bat
Expand Down Expand Up @@ -80,6 +81,7 @@ set CMAKE_GENERATOR_PLATFORM=x64
```

## Debugging

Using [PHPBrew](https://github.com/phpbrew/phpbrew) to build/manage multiple versions of PHP is helpful.

Note: You must use a debug build of PHP to debug native extensions.
Expand All @@ -96,13 +98,20 @@ $ ./configure
$ make CMAKE_BUILD_TYPE=Debug
```

Ensure that the php you launch from your debugger is the result of `which php`, not just
Ensure that the php you launch from your debugger is the result of `which php` , not just
the system default php.

## Security

See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

## Known OpenSSL related issue (Unix only)

* When your php loads a different version of openssl than your system openssl version, awscrt may fail to load or weirdly crash. You can find the openssl version php linked via: `php -i | grep 'OpenSSL'`, and awscrt linked from the build log, which will be `Found OpenSSL: * (found version *)`

The easiest workaround to those issue is to build from source and get aws-lc for awscrt to depend on instead.
TO do that, same instructions as [here](#building-from-github-source), but use `USE_OPENSSL=OFF make` instead of `make`

## License

This project is licensed under the Apache-2.0 License.
2 changes: 2 additions & 0 deletions ext/php_aws_crt.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
# define XRETURN_STRING(s) RETURN_STRING(s, 1)
# define XRETVAL_STRINGL(s, l) RETVAL_STRINGL(s, l, 1)
# define XRETVAL_STRING(s) RETVAL_STRING(s, 1)
/* zend_error_noreturn is not public until PHP7, but may still be visible with some PHP 5.X distributions */
# define zend_error_noreturn zend_error
#endif /* PHP 5.x */

#include "api.h"
Expand Down

0 comments on commit 1926277

Please sign in to comment.