How Do I Build My First PHP Extension in C on Linux GCC?
extension for this example.
<?php
function hello_world() {
return 'Hello World';
}
?>
### config.m4PHP_ARG_ENABLE(hello, whether to enable Hello
World support,
[ --enable-hello Enable Hello World support])
if test "$PHP_HELLO" = "yes"; then
AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World])
PHP_NEW_EXTENSION(hello, hello.c, $ext_shared)
fi
### php_hello.h#ifndef PHP_HELLO_H
#define PHP_HELLO_H 1
#define PHP_HELLO_WORLD_VERSION "1.0"
#define PHP_HELLO_WORLD_EXTNAME "hello"
PHP_FUNCTION(hello_world);
extern zend_module_entry hello_module_entry;
#define phpext_hello_ptr &hello_module_entry
#endif
#### hello.c#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_hello.h"
static function_entry hello_functions[] = {
PHP_FE(hello_world, NULL)
{NULL, NULL, NULL}
};
zend_module_entry hello_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_HELLO_WORLD_EXTNAME,
hello_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
#if ZEND_MODULE_API_NO >= 20010901
PHP_HELLO_WORLD_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_HELLO
ZEND_GET_MODULE(hello)
#endif
PHP_FUNCTION(hello_world)
{
RETURN_STRING("Hello World", 1);
}
Building Your Extension
$ phpize
$ ./configure --enable-hello
$ make
After running each of these commands, you should have a hello.so
extension=hello.so to your php.ini to trigger it.
php -r 'echo hello_world();'
you are done .;-)
read more here
for Easy way to just try zephir-lang to build php extension with less knowledge of
namespace Test;
/**
* This is a sample class
*/
class Hello
{
/**
* This is a sample method
*/
public function say()
{
echo "Hello World!";
}
}
compile it with zephir and get test extension
Using Hiphop for PHP extension development
As far as I know, the point of HipHop is to bypass PHP's Virtual Machine known as Zend Engine.
In order to create a PHP extension, you have to hook into the Zend Engine.
So if HipHop bypasses the execution done by ZE, I don't see how it'd be possible to create a PHP class that gets translated to C++ one that would then be used to create an extension.
HipHop doesn't convert PHP source code, it converts the BYTE code. It's a huge difference, if it were the former.. would there be a need for using another language? :)
Related Topics
What Is the Advantage of Using Try {} Catch {} Versus If {} Else {}
Resetting MySQL Root Password with Xampp on Localhost
Doctrine - How to Print Out the Real SQL, Not Just the Prepared Statement
How to Implode Array with Key and Value Without Foreach in PHP
Dynamic Paypal Button Generation - Isn't It Very Insecure
Mysql_Escape_String VS MySQL_Real_Escape_String
Using Wget to Run a Cronjob PHP
How to Redirect Back to Form with Input - Laravel 5
Pdo Try-Catch Usage in Functions
What's the Most Efficient Test of Whether a PHP String Ends with Another String
Laravel Migration Table Already Exists, But I Want to Add New Not the Older
How to Display Xml in HTML in PHP
How Is Testing the Registry Pattern or Singleton Hard in PHP