All Projects → improved-php-library → skeleton-php-ext

improved-php-library / skeleton-php-ext

Licence: MIT license
Skeleton project for PHP extension (written in C)

Programming Languages

powershell
5483 projects
PHP
23972 projects - #3 most used programming language
M4
1887 projects
c
50402 projects - #5 most used programming language
CMake
9771 projects
Makefile
30231 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to skeleton-php-ext

php aho corasick
Aho-Corasick string search algorithm PHP extension implementation.
Stars: ✭ 45 (+87.5%)
Mutual labels:  php-extension, pecl
pdo sqlcipher
SQLCipher PDO (PHP Data Objects) driver
Stars: ✭ 17 (-29.17%)
Mutual labels:  php-extension
Cphalcon
High performance, full-stack PHP framework delivered as a C extension.
Stars: ✭ 10,534 (+43791.67%)
Mutual labels:  php-extension
nanobox-engine-php
Engine for running PHP apps on Nanobox
Stars: ✭ 20 (-16.67%)
Mutual labels:  php-extension
Ycdatabase
The lightest php database framework written in c language, built in php extension, for mysql
Stars: ✭ 130 (+441.67%)
Mutual labels:  php-extension
php-smartcrop-extension
smartcrop implementation in php extension
Stars: ✭ 17 (-29.17%)
Mutual labels:  php-extension
Php Rdkafka
Production-ready, stable Kafka client for PHP
Stars: ✭ 1,703 (+6995.83%)
Mutual labels:  php-extension
zephir-docs
Zephir Documentation and website
Stars: ✭ 62 (+158.33%)
Mutual labels:  php-extension
php-zookeeper
A PHP extension for interfacing with Apache ZooKeeper
Stars: ✭ 143 (+495.83%)
Mutual labels:  pecl
xray
X-Ray - PHP Engine compiler hook API (new)
Stars: ✭ 19 (-20.83%)
Mutual labels:  php-extension
ansible-role-php-pecl
Ansible Role - PHP PECL extension
Stars: ✭ 29 (+20.83%)
Mutual labels:  pecl
Pht
A new threading extension for PHP
Stars: ✭ 175 (+629.17%)
Mutual labels:  php-extension
php-mustache
Mustache PHP Extension
Stars: ✭ 55 (+129.17%)
Mutual labels:  php-extension
Php Zephir Parser
The Zephir Parser delivered as a C extension for the PHP language.
Stars: ✭ 129 (+437.5%)
Mutual labels:  php-extension
pecl-teds
Tentative Extra Data Structures for php
Stars: ✭ 25 (+4.17%)
Mutual labels:  pecl
V8js
V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
Stars: ✭ 1,659 (+6812.5%)
Mutual labels:  php-extension
Php V8
PHP extension for V8 JavaScript engine
Stars: ✭ 197 (+720.83%)
Mutual labels:  php-extension
php-bencode
C++ PHP extension which can boost the process of encoding and decoding of Bencode.
Stars: ✭ 16 (-33.33%)
Mutual labels:  php-extension
Tensor
A library and extension that provides objects for scientific computing in PHP.
Stars: ✭ 146 (+508.33%)
Mutual labels:  php-extension
php-to-zephir
Convert PHP 7 files to Zephir zep files and create a native PHP extension
Stars: ✭ 25 (+4.17%)
Mutual labels:  php-extension

improved PHP library

Skeleton PHP extension

Build Status Build status

Skeleton project for PHP C-extension.

All other PHP extension skeletons that are available, including the one generated by PHP, are too minimalistic for practical use. Use this skeleton instead.

Includes;

  • Travis (Linux) and AppVeyor (Windows) configuration for continuous integration / platform tests.
    • Automatic deployment of package to GitHub releases
  • CMake config for editing in CLion. (See this article)
  • Supported for pecl dependencies.

> Create a new repository, using the skeleton php extension as template.


Requirements

  • PHP 7.x or 8.x

Installation

phpize
./configure
make
make test
make install

Add the following line to your php.ini

extension=skeleton.so

To try out the extension, you can run the following command

php -a -d extension=modules/skeleton.so

Functions

skeleton_nop

Return the input (which must be a string).

string skeleton_nop(string input)

Customize

To customize this skeleton for your own extension (e.g. foo_bar), edit the following files;

config.m4 and config.w32

  1. Do a search/replace for HAVE_SKELETON, into HAVE_FOO_BAR.

  2. Do a search/replace for the word skeleton into foo_bar.

  3. If your extension name has name underscore, change the enable argument so it uses a dash.

    PHP_ARG_ENABLE(foo_bar, whether to enable foo_bar, [ --enable-foo-bar   Enable foo_bar])
    
    ARG_ENABLE("foo-bar", "enable foo_bar", "no");
    

php_skeleton.h

  1. Rename the file using your extension name php_foo_bar.h.
  2. Do a search/replace for PHP_SKELETON_H into PHP_FOO_BAR_H.
  3. Do a search/replace for HAVE_SKELETON into HAVE_FOO_BAR.
  4. Change the zend_module_entry from skeleton_module_entry to foo_bar_module_entry

skeleton.c

  1. Rename the file using your extension name foo_bar.c.
  2. Do a search/replace for PHP_SKELETON_H into PHP_FOO_BAR_H.
  3. Change PHP_SKELETON_EXTNAME to PHP_FOO_BAR_EXTNAME
  4. Change the zend_module_entry from skeleton_module_entry to foo_bar_module_entry
  5. In ZEND_GET_MODULE replace skeleton to foo_bar.

.appveyor.yml and .travis.yml

Change skeleton with your extension name for the EXTNAME env var.

env:
  EXTNAME: foo_bar

Deployment

Both Travis and AppVeyor are configured to automatically deploy the generated packages to GitHub releases. In order to do so, you need to specify a GitHub API key.

  1. Create a new Personal access token on GitHub via developer settings with the public_repo privilege.
  2. For AppVeyor, encrypt the token using the online Encrypt Yaml tool. Replace <your encrypted toke> for the encrypted value in .appveyor.yml.
  3. For Travis, install the Travis CLI (gem install travis) and use travis encrypt to encrypt the token. Replace <your encrypted toke> for the encrypted value in .travis.yml.

LICENSE

Update the LICENSE with your (company) name and the year.

You may put your name in CREDITS, but don't add you e-mail address or the build may fail.

Replace example function

Edit the header (php_foo_bar.h) and source (foo_bar.c) file, replace the declaration and implementation of PHP_FUNCTION(skeleton_nop) with your own function(s). Also update zend_function_entry functions and create the argument info for each function.

PECL package

If you wish to publish your extension to pecl.php.net, you need your package to contain a valid package.xml. Create this via

make package.xml

You can enter the release notes manually or pipe it from a source like a git commit

git log -1 --pretty=%B | make package.xml

The version is determined base on the version defined in your main header file. Make sure this is correct prior to running make package.xml.

When package.xml is first created, not all fields are filled out. Edit the file manually to fill this fields and verify it with

pecl package-validate

The make command will automatically update the package content entry and include all source and test files. Other files can be added manually. The script will only remove files that no longer exist.

Getting started with PHP internals

There is a lot of information about the internals and writing PHP extensions online. Unfortunately but this information is often outdated, including the information found in the PHP manual.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].