Page 1 of 1
Developing PHP extensions for Linux
Posted: Sat Aug 05, 2006 1:35 pm
by anroy
I am not sure if this is the right place to post this, but I am creating extensions for Linux.
It is tough because I come from a Windows background and it is difficult to compile programs in Linux. There are a lot of environmental complexities, especially to do with paths and libraries.
In the PHP source code download, there is an ext folder containing the source for the various extensions that ship with PHP. Alas, none of them are easy to understand. I am just looking for a trivial "Hello World" example of extension-building.
I do not have time to learn much about gcc or Linux generally, I just need an example that works out of the box. I will just change/add the C code.
Does anyone know where such an example can be found?
Thanks!
Posted: Sat Aug 05, 2006 1:47 pm
by alex.barylski
I think your SOL...
It's complex and therefore few have done it, so therefore there are few articles, those you find on Zend/PHP web site are about all I could ever find...
Posted: Sat Aug 05, 2006 2:48 pm
by Ollie Saunders
I am not sure if this is the right place to post this, but I am creating extensions for Linux.
Probably not. I never seen a post about this before.
a trivial "Hello World" example of extension-building.
I'm guessing you've tried google.
I do not have time to learn much about gcc or Linux generally
Well then you aren't going to get very far I imagine. I have looked into it a little and the only thing I can remember from doing so was that it requires a lot of patience and learning.
What are you trying to achieve anyway?
What makes you so sure that writing your own extension will be necessary?
If performance is your concern there are plenty of ways of improving PHP performance.
Re: Developing PHP extensions for Linux
Posted: Sat Aug 05, 2006 6:32 pm
by Chris Corbyn
anroy wrote:I am not sure if this is the right place to post this, but I am creating extensions for Linux.
It is tough because I come from a Windows background and it is difficult to compile programs in Linux. There are a lot of environmental complexities, especially to do with paths and libraries.
In the PHP source code download, there is an ext folder containing the source for the various extensions that ship with PHP. Alas, none of them are easy to understand. I am just looking for a trivial "Hello World" example of extension-building.
I do not have time to learn much about gcc or Linux generally, I just need an example that works out of the box. I will just change/add the C code.
Does anyone know where such an example can be found?
Thanks!
IMO compiling code on Linux is easier than windows.... it's such common practise even for non-programmers since that's how we often install apps and the compilers are almost expected to just be there. GNU provides nice tools to make it easier to package your code up for others to compile too (automake, buildconf etc).
Writing PHP extensions... well, if you know C then it's actually pretty simple.
Here's your "Hello World!" example you were asking for
http://www.zend.com/php/internals/exten ... iting1.php (Most of that code is skeleton stuff)
`phpize' will make your extension work with your PHP installation for testing.
Posted: Sat Aug 05, 2006 6:59 pm
by volka
Posted: Sat Aug 05, 2006 10:58 pm
by anroy
I'm guessing you've tried google.
You bet!
Well then you aren't going to get very far I imagine. I have looked into it a little and the only thing I can remember from doing so was that it requires a lot of patience and learning.
That is what I am worried about. I personally have the patience, but my company doesn't.
What are you trying to achieve anyway?
What makes you so sure that writing your own extension will be necessary?
If performance is your concern there are plenty of ways of improving PHP performance.
Yes, totally, performance is the issue. My program is a very mathematically intensive one, used on the back-end of a web service.
Now the math is not all that advanced, just a bunch of multiplications and divisions. But there are
millions and millions of them through a loop.
I wonder how much this can be optimized in PHP. Particularly since it is a web service the user is forced to wait for it. It will run much faster in C for sure.
Re: Developing PHP extensions for Linux
Posted: Sat Aug 05, 2006 11:03 pm
by anroy
IMO compiling code on Linux is easier than windows.... it's such common practise even for non-programmers since that's how we often install apps and the compilers are almost expected to just be there. GNU provides nice tools to make it easier to package your code up for others to compile too (automake, buildconf etc).
That is what many people say. But there is a learning curve. In Windows it is all nicely set up for you with Visual C++ whereas in Linux it is all command line. I think I will get used to it but unfortunately right now there are severe time pressures.
Writing PHP extensions... well, if you know C then it's actually pretty simple.
For me, the C part is very easy! It is the whole environment stuff that boggles the mind.
Thank you for the link, it looks pretty friendly and written simply. Will definitely check this one out, it may just be the thing that saves me!
Posted: Sat Aug 05, 2006 11:04 pm
by anroy
I am actually not sure what PEAR is.
I see the word a lot, in anything related to PHP. I would rather not have to worry about a new thing like that. But thanks for the link, will check it out if I have time!
Posted: Sun Aug 06, 2006 3:33 am
by volka
anroy wrote:I am actually not sure what PEAR is.
The php source package contains the script ext/ext_skel that can be used to create an extension skeleton.
But afaik its not maintained any longer.
http://pear.php.net/package/CodeGen_PECL wrote:CodeGen_PECL (formerly known as PECL_Gen) is a pure PHP replacement
for the ext_skel shell script that comes with the PHP 4 source.
It reads in configuration options, function prototypes and code fragments
from an XML description file and generates a complete ready-to-compile
PECL extension.
Posted: Sun Aug 06, 2006 6:50 am
by Ollie Saunders
dw about PEAR its the place where all the terrible PHP code is locked away.
Could you post your code please? I might be able to speed it up.
Posted: Mon Aug 07, 2006 11:49 pm
by anroy
ole wrote:dw about PEAR its the place where all the terrible PHP code is locked away.
Could you post your code please? I might be able to speed it up.
I appreciate the kind offer, thanks.
However it is confidential technology and my employers would kill me. Not that it is anything great, but they seem to think so. Tech companies all suffer from the same hubris.
Anyway, the logic just consists of a sequence of some arithemetic operations. Adds, subtracts, multiplications and divisions on 12-tuple arrays of floating points. This logic is applied on hundreds of thousands of DB records, each of which contains that 12-tuple of floats.
The MySQL DB access is not the cause of the slowness. I read in all the records first and set up the arrays. I have confirmed that this step is very quick. It is looping through
all of them doing those arithmetic operations that takes time.
I know a few optimization tricks from my younger days as a C++ game programmer, such as multiplying by 0.5 rather than dividing by 2, and stuff like that.
Do you have such a bag of tricks you can share, or refer me to?
I am not sure if the common-sense rules in the C/C++ world also apply to PHP. I programmed in those languages for 15 years but have been doing PHP only a few months.
Posted: Tue Aug 08, 2006 12:24 am
by Weirdan
Adds, subtracts, multiplications and divisions on 12-tuple arrays of floating points. This logic is applied on hundreds of thousands of DB records, each of which contains that 12-tuple of floats.
Just curious, what is it for?

Posted: Tue Aug 08, 2006 7:20 am
by anroy
Weirdan wrote:Adds, subtracts, multiplications and divisions on 12-tuple arrays of floating points. This logic is applied on hundreds of thousands of DB records, each of which contains that 12-tuple of floats.
Just curious, what is it for?

Sorry, that is confidential right now. I will give you guys the URL in a few months when this thing is complete... but if I cannot speed it up it will not go live.
