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

creating PHP C/C++ extension modules using SWIG

I have written some C/C++ extension modules for PHP, using the 'old fashioned way' - i.e. by using the manual way (as described by Sarah Golemon in her book). This is too fiddly for me, and since I am lazy, and would like to automate as much as…
morpheous
  • 16,270
  • 32
  • 89
  • 120
15
votes
3 answers

List used PHP modules in code base

I need to list all PHP extensions that's required by a given code base. What would be the best way to tackle this problem? My initial thought is to write a script that goes through all files and find all functions and compare them to a given…
ibrahim
  • 151
  • 1
  • 3
15
votes
3 answers

Getting Started with PHP Extension-Development

Please suggest help articles or tutorials about PHP "low" level С-modules programming interface.
duganets
  • 1,853
  • 5
  • 20
  • 31
14
votes
1 answer

7z extension for php?

I can't find one and I don't know if any of PHP Compression and Archive Extensions will work. Do you think I could use a compression stream to read data from a 7z file? UPDATE 7z forums have a lot of requests for a php extension
Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114
14
votes
3 answers

Extending PHP with C++?

I have a performance intensive routine that is written in PHP that I'd like to port to C++ for a performance increase. Is there any way to write a plugin or extension or something using C++ and interface with it from PHP? WITHOUT manually editing…
ryeguy
  • 65,519
  • 58
  • 198
  • 260
13
votes
2 answers

Install/activate PHP "intl" extension running MAMP

Ok, I'm running MAMP 1.9.5, which includes PHP 5.3.5, on my MacBook Pro. The "intl" extension isn't included/activated and I've tried a lot of different ways to install it ("./pecl install intl" doesn't seem to do it), but can't make it work. I've…
Manne W
  • 1,459
  • 4
  • 17
  • 31
13
votes
3 answers

Use php extensions in Google Cloud App Engine

I'm trying to run a symfony4 application in the Google Cloud App Engine following this instructions. My app has a dependency which itself depends on php-gd. This extension seems to be unavailable since composer fails with the requested PHP extension…
13
votes
6 answers

Detect if the FreeType PHP extension is installed on the server

How do I test to see if the FreeType extension is installed on a server running PHP? I wanted to make a simple CAPTCHA system on my site, so I used imagettftext() and it worked fine. But what if the server didn't have the FreeType library…
Bluemagica
  • 5,000
  • 12
  • 47
  • 73
13
votes
3 answers

How to automatically enable php extensions in Homestead on vagrant up

Im using Laravel 5.3 in Homestead with Vagrant 1.8.7 running on VirtualBox. I have need to enable some php extensions. I know that I could ssh into the box and edit the php.ini to enable the extension but this seems like a very anti-vagrant way to…
Wesley Smith
  • 19,401
  • 22
  • 85
  • 133
13
votes
2 answers

How can I wrap a c++ class in php extension?

I created 4 files to wrap a c++ class in php Extension.Now I want to run the code for wrapping.But I have no idea about that.How can I run the code? I'm following the tutorial over at http://devzone.zend.com/article/4486, and here's the Graph code I…
user1422892
  • 195
  • 2
  • 3
  • 15
12
votes
1 answer

Compiled PHP extension is not valid

I am trying to install the gearman PHP extension on Ubuntu 10.04 with PHP pinned to 5.2, but PHP is telling me it's not a valid Zend extension. There are no errors when compiling from source (or installing via pecl), but after it's installed, PHP…
Brian
  • 15,599
  • 4
  • 46
  • 63
12
votes
2 answers

Is it possible to create PHP extensions in Haskell?

Is it possible to create PHP extensions with Haskell? Usually PHP extensions are written using C. Is using Haskell FFI to provide functionality for a stub C extension possible (or even a good idea)? What are the caveats to such an approach? Does…
Anupam Jain
  • 7,851
  • 2
  • 39
  • 74
12
votes
3 answers

Memcache PHP extension on windows 10 works intermittently

I have memcache extensions on apache/php windows 10 (details at the end) Created a simple test: $memcache = new…
Nir
  • 24,619
  • 25
  • 81
  • 117
11
votes
1 answer

zend custom module

I am trying to build my own zend module (.so) We have multiple functionality that can be done in our own module which will improve our performance on a high traffic website (50k+ visits a day). These are simple module but I was wondering is the…
Erin Tucker
  • 3,274
  • 2
  • 15
  • 22
11
votes
3 answers

PHP Windows extensions won´t load

I'm working on a windows server 2008 R2 machine. I have installed apache 2.2 with php 5.4.25 While trying to enable ldap support for the apache server i found out that the server does not load the extensions. I ran php_info() and this was the…
squirreldev
  • 517
  • 2
  • 8
  • 18
1 2
3
67 68