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
3
votes
1 answer

Helm + Kubernetes, load and enable extensions or modules in PHP

i've problem when i run a php deployment with kubernetes becouse don't load the modules or extensions libraries. My deployment file is this: apiVersion: apps/v1 kind: Deployment metadata: name: php labels: app: php spec: selector: …
O.Palm
  • 162
  • 1
  • 3
  • 15
3
votes
1 answer

Install mysqli on php-7.2.11, but "Unable to load dynamic library 'mysqli.so'"

I have installed the php-7.2.11 on linux successfully but forgot the extensions mysqli. I made the mysqli.so and installed it on "/usr/local/lib/php/extensions/no-debug-non-zts-20170718". If I run the "php -m",there is a mysqli, but when I start the…
Hanamaki
  • 29
  • 1
  • 2
3
votes
2 answers

Use PHP functions in PHP extension

Can I use a PHP function such as explode() when creating an extension in C++?
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
3
votes
1 answer

ldap_set_rebind_proc() function does not work in any PHP Windows distribution

The problem is: ldap_set_rebind_proc() function does not work in any PHP Windows distribution error obtained when executing the php file: Undefined function ldap_set_rebind_proc() PHP tested versions (5.* y 7.*), I've even tried it on PHP versions…
3
votes
1 answer

SWIG for making PHP extensions, have you tried it?

I have a few small libraries and wrappers written in C (not C++) that I would like to make available to PHP via extensions. I read several tutorials on writing proper PHP extensions and it does not seem to difficult, however I don't want the hassle…
Tim Post
  • 33,371
  • 15
  • 110
  • 174
3
votes
1 answer

PHP Zend Engine Extension and static methods

On writing an extension for php (5.3) i want to access the zend_class_entry pointer on a static method. On non static methods i can use the getThis() macro and within Z_OBJCE_P macro like this: zend_class_entry ce* = Z_OBJCE_P(getThis()); Now the…
sassman
  • 81
  • 5
3
votes
1 answer

PHP install mailparser extension

I want to install mailparser extension. I downloaded php_malparse.dll ( put it to php/ext folder). Also added : extension=php_mailparse.dll to php.ini But it doesn't work, and php_info() doesn't show it too. In logs I get: PHP Warning: PHP…
babboe1 babboe1
  • 51
  • 1
  • 2
  • 3
3
votes
2 answers

PHP extensions - call your own PHP function from another PHP function

Let's say we have a custom PHP extension like: PHP_RSHUTDOWN_FUNCTION(myextension) { // How do I call myfunction() from here? return SUCCESS; } PHP_FUNCTION(myfunction) { // Do something here ... RETURN_NULL; } How can I call…
m1tk4
  • 3,439
  • 1
  • 22
  • 27
3
votes
0 answers

Homebrew throwing unable to load dynamic library error with all versions of PHP on macOS Sierra

When I install PHP using Homebrew, any extensions that I attempt to load (including the core extensions such as mysqli and gd2) throw an Unable to load dynamic library error during any usage. Is there a solution available? The error thrown is as…
Forest
  • 938
  • 1
  • 11
  • 30
3
votes
2 answers

XXHash for PHP (without module/extension)

For on online service, I'm currently using XXHash. Now I'm trying to create a plugin for webshops but these shops are all using PHP, mostly on shared hosting platforms. Problem with this is that the available XXHash plugins all require to have…
spa900
  • 927
  • 9
  • 19
3
votes
1 answer

Call object constructor (__construct) from a php extension

I'm just experimenting with a PHP extension and I would like to know what is the suggested/preferred way to call an object constructor within the extension. I've read that, by calling the object_init_ex function the constructor of that object is not…
3
votes
1 answer

Expose version of extension in phpinfo() output

When writing custom extensions for PHP, you usually define a version string in the header file of your extension, e.g. something like #define PHP_MYEXT_VERSION "0.1.0" PHP will then use this to provide information about the extension's version when…
Gordon
  • 312,688
  • 75
  • 539
  • 559
3
votes
1 answer

PHP Extension: How to return a new class object

I am creating an extension that has multiple classes and some of them have methods that should return instances of another class. This is for PHP 7+ and not for anything else. For example, I need the PHP code to be something like this (I'm creating…
markzz
  • 1,185
  • 11
  • 23
3
votes
1 answer

What's the best method to load a dll in php?

I'm developing a web app using CakePHP on the server side, and I need to use a dll provided by a 3rd party to access their platform, so I don't have the source code of the dll and I can't modify it. I've searched about this and I haven't found a…
3
votes
3 answers

Compiling a php extension with Visual Studio 2008, MODULE ID don't match with php

After compiling my own php extension using VC9 (2008) and VC10 (2010) using the next steps: http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/ I get the next error when initializing php: PHP Warning: PHP Startup:…
Wiliam
  • 3,714
  • 7
  • 36
  • 56