Questions tagged [php-extension]

The PHP language can be enhanced through the use of extensions, which provide to PHP scripts new internal functions, classes, resource types, streams (also stream wrappers and filters) and, in general, can do anything a native program would be able to do.

The PHP language can be enhanced through the use of extensions, which provide to PHP scripts new internal functions, classes, resource types, streams (also stream wrappers and filters) and, in general, can do anything a native program would be able to do. Extensions are typically written in order to:

  • Wrap a native library, which is typically written in C or C++.
  • Implement PHP code in a language that offers more optimization opportunities, such as C, so that pages can be served faster and/or more pages can be served concurrently.
  • Implement/functions classes that, being closer to PHP's core, are able to do things that would otherwise not be possible (e.g. add/remove functions from the function table dynamically, bypass open_basedir).

PHP is written in C and has a C API available for extensions, therefore these tend to be written in that language. However, the only requirement is that the resulting extension is able to interface with PHP's APIs, handle its data structures and can be loaded by PHP's extension loading mechanism.

SWIG can be used to wrap native libraries in an easier fashion. See also PHP4Delphi, which allows embedding PHP in Delphi and other applications as well as writing PHP extensions in Delphi.

A special type of extensions, Zend extensions, are more tightly coupled with PHP and are provided with more hooks so that they can modify PHP's behavior more extensively. They are typically used to implement debuggers (e.g. XDebug).

Unfortunately, there is no official and up-to-date reference on how to write PHP extensions. However, see this answer for several resources.

1016 questions
4
votes
1 answer

php: delete shared memory on windows

This code: shmop_delete(); shmop_close(); doesn't delete shared memory. An experiment: $shmid = @shmop_open(1234, 'a', 0, 0); var_dump($shmid); yields bool(false) of course. But $shmid = shmop_open(5678, 'c', 0644,…
user1592714
  • 443
  • 4
  • 11
4
votes
1 answer

How can i install gearman php extension on Windows OS?

Please anybody help me out in installing gearman php extension on windows xp. I have xampp 1.7.7 installed on my system and i have installed Cygwin, libevent-1.4.14b-stable and gearmand on my system. Please let me know what more is needed to install…
udaydesai08
  • 53
  • 1
  • 6
4
votes
1 answer

How do I add an array as an Object Property to a class declared within a PHP extension?

I want my PHP extension to declare a class equivalent to the following PHP: class MyClass { public $MyMemberArray; __construct() { $this->MyMemberArray = array(); } } I'm following the examples in "Advanced PHP Programming"…
John Carter
  • 53,924
  • 26
  • 111
  • 144
4
votes
2 answers

Is the PHP Intl extension thread safe?

I've been reading about locales in PHP and it seems setlocale() has problems with threads. (I'm not too familiar with threads - the docs mention it is not thread safe) I'd like to give my project the ability to deal with certain number formats and…
RS7
  • 2,341
  • 8
  • 34
  • 57
4
votes
4 answers

Documenting a PHP extension with PHPdoc

I've written a PHP extension in C, and I want to create PHPdoc documentation so that my users will get inline docs in their PHP IDE (in this case, Netbeans) when calling my extension. Ideally I'd like to do this by embedding the PHPdocs in the C…
John Carter
  • 53,924
  • 26
  • 111
  • 144
4
votes
3 answers

unloading php extensions : reverse dl()

To you gurus out there, is there any hidden gem in PHP that could unload a specific extension at runtime ?
Justin T.
  • 3,643
  • 1
  • 22
  • 43
4
votes
2 answers

Creating static libraries

I'm trying to create a static library to use inside my PHP extension. To do that, I'm compiling my .c files using gcc -c file.c -o file.o and obtaining .o files. I then use ar rcs lib.a *.o to archive all the compiled objects into an .a file. After…
rid
  • 61,078
  • 31
  • 152
  • 193
3
votes
0 answers

How can I generate skeleton of classes from PHP extension for code completion in IDE?

Some years ago I found somewhere simple script that was able to generate skeletons for classes, functions and constants from some extension. U think it used Reflection. I don't remember, but I think this script was on zend.com web site or somewhere…
Max Romanovsky
  • 2,824
  • 5
  • 30
  • 37
3
votes
1 answer

How to return $this in a php Extension?

For example this method of Dataset object returns NULL, How do I make it to return $this PHP_METHOD(TSet, nextLine) { TSet *MySet; tset_object *obj = (tset_object *)zend_object_store_get_object(getThis() TSRMLS_CC); MySet =…
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
3
votes
1 answer

Imagick is recognized by WAMPServer but not by PHP

ImageMagick is installed correctly. WAMP'S "PHP Extension" menu also shows php_imagick with a check. phpinfo() shows no trace of the imagick extension except for Apache and System Environment Variables. All paths are correctly specified.
Davide Valdo
  • 164
  • 2
  • 10
3
votes
3 answers

PHP Extension: Works from command line, but not in httpd (Apache) server

I'm getting the strangest problem with my PHP extension. When I use it from the command line, like so: php -r '$mc = new MyClass("foo"); echo $mc->getField();' it prints out "foo" as expected. However, if I try to do the same thing from within my…
Ben
  • 7,692
  • 15
  • 49
  • 64
3
votes
1 answer

zend_call_method_with_N_params

There are zend_call_method_with_0_params, zend_call_method_with_1_params and zend_call_method_with_2_params in PHP extension development. But how to call method with more than 2 params?
Eugene Manuilov
  • 4,271
  • 8
  • 32
  • 48
3
votes
1 answer

php dl() for loading extensions is removed from some SAPIs

I'm reading on the dl() function (which lets you load extensions manually), and the php documentation says WARNING: This function has been removed from some SAPI's in PHP 5.3. Does anyone know what this means. SAPI seems to mean Server API, but…
sameold
  • 18,400
  • 21
  • 63
  • 87
3
votes
4 answers

How do I check for an unmangled C++ symbol when building a PHP extension?

I have a PHP module written in C++, which relies on a C++ library (Boost Date_Time) being installed. Currently, in my config.m4 file I'm checking for the library as follows: LIBNAME=boost_date_time LIBSYMBOL=_ZN5boost9gregorian9bad_monthD0Ev …
John Carter
  • 53,924
  • 26
  • 111
  • 144
3
votes
1 answer

PHP extension version inconsistencies; a more reliable way?

Having run the following: foreach(get_loaded_extensions() as $name){ $extensions[strtolower($name)] = phpversion($name); } var_dump($extensions); I notice that some of the loaded extensions don't show a version, having false instead, for…
Dan Lugg
  • 20,192
  • 19
  • 110
  • 174