https://github.com/phwoolcon/php-sapihack
PHP Extension: SAPI Hack
https://github.com/phwoolcon/php-sapihack
Last synced: 19 days ago
JSON representation
PHP Extension: SAPI Hack
- Host: GitHub
- URL: https://github.com/phwoolcon/php-sapihack
- Owner: phwoolcon
- License: apache-2.0
- Created: 2017-08-24T12:13:23.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-25T12:23:06.000Z (almost 9 years ago)
- Last Synced: 2025-02-28T23:38:33.780Z (over 1 year ago)
- Language: C
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-sapihack
PHP Extension: SAPI Hack
## Use case
Headers are not used completely in CLI mode, but `headers_sent` is always set to `1`
if any content is echoed on the screen, then we get unexpected annoying error with
message `headers already sent`
Use this extension to avoid such errors and keep running smoothly in CLI mode, especially
in PHP 7.2, some `session_` functions behaves different than older versions:
* `session_name()`
* `session_set_save_handler()`
* `session_save_path()`
This check (`headers already sent`) is necessary in CGI mode, but this should not happen
in CLI mode, for example, when we running `swoole` or `phpunit`.
## Installation
```bash
git clone git@github.com:phwoolcon/php-sapihack.git
phpize
./configure --enable-sapihack
make
sudo make install
echo 'extension = sapihack.so' > /etc/php/7.2/mods-available/sapihack.ini
sudo ln -s ../../mods-available/sapihack.ini /etc/php/7.2/fpm/conf.d/20-sapihack.ini
sudo ln -s ../../mods-available/sapihack.ini /etc/php/7.2/cli/conf.d/20-sapihack.ini
service php7.2-fpm restart
```
## Documentation
### Constants
`SAPIHACK_VERSION`
`SAPIHACK_VERSION_ID`
### Functions
#### sapihack_reset_headers_sent()
**WARNING** Only use this function in CLI mode.
```php