Win32 PHP extension development - php

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

Related

How to install SAPRFC with PHP 5.4.4 in Windows 32 system?

I've tried a lot of things given over the internet to setup SAPRFC in Windows but they all are talking about PHP 5.2 version but everyone knows that we are using PHP 5.x nowadays.
I'm running Xampp server where my PHP version is 5.4.4 and I need to communicate with SAP server through PHP script. I've tried the procedure of copying librfc.dll in system32 folder and php_saprfc.dll in php/ext folder and also modification of php.ini but it doesn't help me.
I have to following instructions:
Installation:
Extract zip file saprfc-$VERSION$-$PHP_VERSION$.zip
Copy php-saprfc.dll to your extensions directory (e.g. C:\PHP\extensions)
Edit php.ini file (in windows system directory, e.g. C:\WINNT, C:\WINDOWS) and add line: 'extension=php_saprfc.dll'
Copy librfc32.dll (from SAPGUI install CD) to the Windows system directory or simple install SAPGUI on your machine.
Compilation:
Extract php sources to C:\PHP-x.y.z
Extract php win support files to C:\PHP-x.y.z\win32
Install RFCSDK to C:\PHP-x.y.z\rfcsdk
Copy SAPRFC sources to C:\PHP-x.y.z\ext\saprfc
Copy php4ts.lib or php5ts.lib (from PHP binaries) to C:\PHP-x.y.z\win32
For PHP5 copy saprfc.dsp5 to saprfc.dsp
Open project C:\PHP-x.y.z\ext\saprfc\saprfc.dsp in Microsoft Visual C++ 6.
Under Tools|Option|Directory set path for Include files and for Library files:
(C:\PHP-x.y.z\win32\include; C:\PHP-x.y.z\rfcsdk\include;
C:\PHP-x.y.z\win32\lib; C:\PHP-x.y.z\rfcsdk\lib)
Set active configuration to "saprfc - Windows_TS" (under Build menu)
Build php_saprfc.dll.
Compiled DLL you find in C:\PHP-x.y.z\Release_TS directory
But I'm not getting the compilation part.
The newest version is from 2009 and can be found here. For newer PHP versions you have to compile the extension yourself (at least the docs say so). Seems like the devs didn't make the jump to the newer versions because of the compiler needed. In the compilation docs it still says Microsoft Visual C++ 6.0. AFAIK modern PHP uses 9.0. So you propably need to tinker a bit with it. Or you might ask in the SAP forums if someone did the necessary work already.
You can download precompiled version here:
https://sourceforge.net/projects/saprfcsapnwrfc/files/

How can write or find a PHP extension for Apache Thrift

Apache Thrift now only support PHP source files (copy [thrift-source]/lib/php/lib to own project to use). But, Can i find a .dll PHP extension file instead that? Where can i find it?
Otherwise, i have to write it. Could you tell me how to do that (i usually use Apache server)?
Is that right if I install C++ Lib of Apache Thrift and write PHP extension base on it? Or, can i generate from thrift-source (i have looked cpp files [thrift-source]/lib/php/src/ext, but maybe protocol only)?

How to create a shortcut in php?

Is it possible to create a shortcut that points to in-existing file in php and make it run normally in windows?
Example
makeshortcut("C:\Windows\calc.exe","short.lnk");
Then when I download the shortcut, it would open calc on my computer.
I don't have COM enabled, I do have exec() enabled, so I can run some kind of perl or python, however, lots of extensions are disabled, particlarly (pywin32 and win32::shortcut), so it would be highly appreciated if I can do this only in php or using calling another script with exec() which doesn't require me to install additional extensions.
The linux ln command has nothing to do with Windows .lnk files, and they are not compatible.
Here is some info on the .lnk file format.
As you can see it is not trivial to create from scratch.
liblnk library allows you to read .lnk files in Linux, but I haven't seen one that allows for their creation.
Edit:
Here is a SO question similar to yours:
Generate Windows .lnk file with PHP and Creating a Desktop Shortcut Using a Web Page
You can use http://www.mamachine.org/mslink/index.en.html - a bash and c program to create a shortcut.
Compile the C program for your platform and call it with the shell_exec function.
Even if the question is old, I hope it helps others.

How can I create a PHP extension on Windows?

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/

Understanding extensions in php.ini

I'm having trouble understanding these ;extension=xxx.dll files in php.ini
Is there any document I can refer to which explains these extensions in detail?
The .dll files are for PHP extensions. You can read about all of them here: http://php.net/manual/en/install.windows.extensions.php
PHP extensions give you extra PHP functionality. They are basically function libraries that add features like MySQL functions, LDAP functions, and even Java functions.
To activate the extensions provided by the default PHP install, simply uncomment the ;extension=xxx.dll line (remove the semicolon) so that it just looks like extension=xxx.dll.
However, not all extensions are bundled with PHP. For example, the PECL extensions, including APC, have to be installed externally. Instructions for installing PECL can be found here: http://www.php.net/manual/en/install.pecl.php
"Extension Writing Part I: Introduction to PHP and Zend"
You only need to worry about those if you're running on a Windows server - since they appear to be commented out (; at the start of the line) I would assume you're on a Linux server?
In any case, you should be able to look up each extension individually on Google.

Categories