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
4 answers

Activating PHP extensions in Bluemix

This is a purely Bluemix question! I've got code running smoothly on a localhost but when I migrated it to Bluemix my DB connection failed me. Checking the logs I found the issue "Call to undefined function mysqli_init()" HTTP response 500. I have…
4
votes
3 answers

PHP Linking to a shared library in an extension

I'm working on a native PHP extension which includes symbols from a shared library, but I can't get the config.m4 file to generate a build procedure that includes the necessary linker options to correctly link to the share library. This is what I…
ironchicken
  • 754
  • 6
  • 19
4
votes
3 answers

How Do I Make a PHP Module with the Vala Programming Language?

This new language called Vala, which is said to be C#-like and supposedly easier than C++ or C, compiles down into C on Linux with the GCC compiler. Sounds great. Now I want to use it to make a PHP extension module so that slow PHP code can be made…
Volomike
  • 23,743
  • 21
  • 113
  • 209
4
votes
0 answers

Visual Studio PHP Tools not formatting code

I'm writing php in Visual Studio using the PHP Tools extension. The code formatting of the PHP Tools doesn't seem to be working. The formatting option is available in the options menu: And I have tried linking the php-extension to the PHP…
4
votes
3 answers

Installing dBase extension in XAMPP

I have a problem with installing dBase extension in XAMPP with PHP 5.5.11. I added php_dbase.dll to php/ext folder and added following line to the php.ini file: extension=php_dbase.dll But when I try this code in my…
user3740742
  • 51
  • 1
  • 1
  • 4
4
votes
0 answers

After enabling fileinfo extension and restarting Apache it still does not load

I want to use fileinfo extension in PHP (5.5). (On localhost(Windows), using XAMPP) So I went to php.ini and commented out extension=php_fileinfo.dll, then I HAVE restarted the apache, even tried to restart the whole PC. But when I try to use it I…
jave.web
  • 13,880
  • 12
  • 91
  • 125
4
votes
2 answers

How to access current php file in php extension (written in c)?

I'm trying to write an extension for php using swig. I need to know the absolute path of the current php file in my extension code. I used __ FILE __ in my C code but it returns current c file name.
Ali choobdar
  • 121
  • 6
4
votes
2 answers

Compiling a PHP extention library on Ubuntu (Karmic Koala)

I compiled some PHP extention libs (in C/C++) a while back, on my XP platform. I have now moved the sources to my Ubuntu box, and want to build the libs for use on my Linux box. However, I have come accross a number of obstacles: I cant locate…
Stick it to THE MAN
  • 5,621
  • 17
  • 77
  • 93
4
votes
4 answers

Can't compile php extension on Maverick OS X

After Update OS X, I see that a lot of my previously build extensions are gone ;( Now I'm trying to compile memcached.so in result I have a lot of errors ;( I installed XCode command line tools and running compilation like this: sudo pecl install…
user1016265
  • 2,307
  • 3
  • 32
  • 49
4
votes
2 answers

How can I install Zephir on Ubuntu?

I would like to install Zephir on my Ubuntu machine. The goal is to convert some of my existing code into a PHP extension, in order to get the benefits of faster execution. Any pointers are more than appreciated.
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
4
votes
1 answer

php-fpm extension listed in phpinfo() fails with "Class not found"

nginx + php-fpm on CentOS, all compiled from sources. Adding memcached support, I compiled libmemcached and php "memcached" extension, added a line `php_admin_value[extension]=memcached.so' in the php-fpm config and restarted php-fpm. Opening a test…
Serge
  • 1,531
  • 2
  • 21
  • 44
4
votes
1 answer

Is there a way to log only executions slower than X with xdebug?

I would like xdebug to trace only "jumps" of over X ms or of over Y KB RAM, for instance, every execution that took longer than 100ms or increased memory use by more than 100KB. This would let me ignore thousands of trace lines I don't need to see…
Swader
  • 11,387
  • 14
  • 50
  • 84
4
votes
1 answer

callbacks in jni

Is there any way to pass a callback to java code, from C. And the call returns immediately. Later on, after completing the task, the java code can invoke that callback. I have a C extension for php that calls a java store to store some items in it.…
ata
  • 8,853
  • 8
  • 42
  • 68
4
votes
1 answer

Compiling a PHP extension for windows

I've previously managed to get XHP compiled in a Linux environment with the .so extension. I'm trying to compile it for use in a windows enviroment (.dll) and I've followed the following tutorial on php.net but after I buildconf, I fail to see the…
Adam
  • 1,214
  • 13
  • 23
4
votes
1 answer

Mcrypt PHP - Module Initialization Failed

How to install the mcrypt modules on PHP? I need to install the mcrypt extension on WAMPServer so that I can use IDEA encryption on passwords. I can't use any other type of encryption, because the large database I am interacting with already uses…
Scott Hallauer
  • 389
  • 2
  • 8
  • 16