How can I create a PHP extension on Windows? - php

More specifically, I'm trying to make a PHP extension for WampServer, which I'm using to test PHP scripts on my PC. I know that a PHP extension requires a config.m4 file, and some C/C++ code to be created within PHP. How would I get these .c/.cpp and .m4 files into a .dll that's required to make a PHP extension?

Take a look at this : Getting Started with PHP Extension-Development
Generally you need C compiler (with or without IDE), I recommend MS Visual C++ Express.
Then follow this tutorial: http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/

Related

Build PHP extension of Saxon for Windows

I need to use XSLT 2.0 with PHP on Windows for a work, and after a few research, it seems that the best way to achieve it is to use the saxon-C of Saxonica.
I followed the official documentation until this point :
The PHP extension has not yet been built. It can be built using the PHP source. [...] To build the PHP extension yourself please see the Saxon-C-API Visual Studio 2008 project included in the installation (e.g. 'C:\Program Files\Saxonica\SaxonHEC1.1.0\Saxon-C-API').
I looked at the file and there are some .h and .cpp files and the config.w32 file, so I tried to build the extension according to this documentation :
http://blog.benoitblanchon.fr/build-php-extension-on-windows/
But I have some error during the process.
Is it the right way to perform it ? Or is there a better way to do it ?
Sorry if the answer is obvious, I'm not a PHP pro.
Thank you in advance for your answer.

Consistency around the .phar extension in PHP

Kind of simple question, but I'm new to php and have spent too much time trying to google a simple question. I'm using php 5.6 and many guides (codeception, for example) talk about running a command like php vendor/bin/codecept.phar. My files often don't have the extension and i don't need to use php to execute them. Is this just something that evolved out of the language and is now optional?
A .phar file is a compressed archive containing one or more PHP files:
The phar extension provides a way to put entire PHP applications into a single file called a "phar" (PHP Archive) for easy distribution and installation.
Source: http://php.net/manual/en/book.phar.php
There is no requirement to run it from the command line with php, just as there is no requirement to run a .php script from the command line with php. As long as the file is marked executable and has an appropriate shebang it can be run as a standalone file.

Mismatch between Php and Extension module

I am trying to install the following php extension. Microsoft Drivers for SQL Server for PHP.
I have tried both versions of the driver but both seem to mismatch the version of php i am running. I looked around and it appears I have to recompile the modules in order to match the php api version. But I don't have any idea how to do this.
Any ideas on how to make this work? Or maybe a simpler way to use PHP 5.4.7 to access SQL.
You can do it with some tricks, its not recommended but it will work fine and in my case, it has not crashed yet :)
Check your phpinfo() page for:
1-PHP extension API Number
2-Thread safe or non-thread safe version
3-(Windows) compiler version
1-For building your extension you need php.lib. It is in your PHP-server dev directory.
2-You need PHP header files for compiling your extension, after including PHP header files, go to PHP/Zend directory and open zend_modules.h file and change the #define ZEND_MODULE_API_NO 20060613to your PHP extension API number for example change it to #define ZEND_MODULE_API_NO 20090626.
3- If you use windows based servers the compiler version is important(VC8 - VC10), if your PHP was compiled with VC8, build the extension in VS2008 or use VC8 for building your project.
If you encounter any wired error just comment it. I spent 3 months to make this worked ;)

Unable to create sample application using Yii Framework

I am new to PHP. downloaded "yii-1[1].1.4.r2429.zip" file. and try to create sample application using Yii PHP framework
Extracted yii-1[1].1.4.r2429.zip to this path.
C:\xampp\htdocs\yii on windows
and try to create sample application using this guidelines
http://www.yiiframework.com/doc/guide/quickstart.first-app
Run yiic on the command line as follows:
not working.
Please help
Double check that you have PHP CLI (command line) installed and added to your Windows path.
Also, make sure you are running yiic.bat - the Windows script. The plain yiic script (no file extension) is a Unix shell script. You want something like this on Win:
YiiRoot/framework/yiic.bat webapp WebRoot/testdrive
If the .bat script doesn't work, call PHP directly to yiic.php, like so:
php path\to\yii\framework\yiic.php webapp path\to\www\ApplicationName
Your might be able to benefit from XAMPP. It comes pre-packaged and sets up a isolated environment for you, that way you don't have to go through installing php, apache and mysql.

Win32 PHP extension development

What are first steps creating a loadable DLL module extension for PHP to create native support for my own library on Windows?
Would it require re-compiling PHP on windows? What are the tools needed? I don't want to have to use exec and the command line.
See for the basic steps to compile PHP or PHP extensions:
https://wiki.php.net/internals/windows/stepbystepbuild
Q. Would it require re-compiling PHP on windows?
A. Not necessarily, but it is the simplest way.
The command line is your best friend (apple, after years of GUI improved MACOS by ... readding the shell back)
I would try the following:
A. Setup a mingw-msys build system on win.
B. Follow PHP Extension Manual:
1. Download PHP Source code
2. Build PHP for Extension Development using the above MSYS
3. Generate a extension skeleton using ext_skel your extension will reside in ext/ directory
4. Edit the config.w32 (is a javascript macro system for Makefile generation similar to m4)
...
Continue by following these:
http://www.php.net/manual/en/internals2.php
http://talks.somabo.de/200610_zend_conf_php_extension_development.pdf

Categories