Page 1 of 2
php .NET and ANSI C
Posted: Sun Jul 30, 2006 4:48 pm
by ngungo
I am a newbie and a so-so .NET developer converting to php. Please bear with me.
I've finished a .NET version of
The Link Grammar, an English syntax parser, now my new assignment is implement a php version of it. What I have is a set of APIs written in ANSI C.
Question is how do I make these APIs php callable.
My knowledge about server is very minimal so here I speculate. The APIs needed to be compiled, installed in some cgi directory, make them php-bound. Am I heading right direction?
Posted: Sun Jul 30, 2006 5:01 pm
by timvw
I think the easiest (most portable) way is to make them available via a php extension..
http://www.zend.com/php/internals/exten ... iting1.php...
Posted: Sun Jul 30, 2006 5:24 pm
by RobertGonzalez
That is a great tutorial. Makes me want to go out and learn C so I can write an extension.
Posted: Sun Jul 30, 2006 5:47 pm
by bg
Everah wrote:That is a great tutorial. Makes me want to go out and learn C so I can write an extension.
Yeah, what little C I've done was written 5 years ago so I'm rusty myself. Definatly would come in handy for server intensive operations. The JSON parser extension is something like 5900% faster than a PHP implementation. For this reason I created a driver system that acts as an abstraction layer for functionality like this. For example I could have a json driver that uses a php implementation, or I could have a json driver that uses the extension.
And to plug this while I'm at it, the project I mention is hosted on google's project hosting here:
http://code.google.com/p/webtpo/
Check it out every so often.
Posted: Sun Jul 30, 2006 6:37 pm
by ngungo
Hi timvw,
Thanks for the clue. I am studying it. I tried to reach you at
timvw@users.sourceforge.net but got an error: "... This is a permanent error; I've given up. Sorry it didn't work out."
Posted: Sun Jul 30, 2006 8:15 pm
by Weirdan
ngungo
not to speak for timvw, but most members here prefer to not offer advices/support via pm/im/email unless they're paid for that. We consider it's better to discuss your issues in public, so others could benefit from the discussion as well.
Posted: Sun Jul 30, 2006 8:46 pm
by ngungo
Weirdan:
Please allow me to be candid and with my humility, here is the error email:
Hi Tim,
=20
You have answered my posts about the Link Grammar. I would not dare to =
hire you to do my job. This is my own research for my Vietnamese parser, =
no commercial value. But would you please help me for a nominal fee. =
Let=E2=80=99s say =E2=80=A6 [ngungo edited]. And what you make would be public =
domain as well.
=20
I don=E2=80=99t need it right away, do it in your spare time.
=20
Respectfully,
ngungo
I was thinking the solution is original, and I was asking him to help with a nominal fee.
Posted: Sun Jul 30, 2006 11:44 pm
by RobertGonzalez
I'd bet if you threw him some money at that email address through Paypal it would work...
Posted: Mon Jul 31, 2006 4:29 pm
by panic!
if you can code php...you can code C, I'm come from a C background and found the two very similar.
Posted: Mon Jul 31, 2006 4:53 pm
by Ambush Commander
if you can code php...you can code C
I would have to disagree. Coding in C requires a much more expansive understanding of lower level structures and algorithms then PHP: you have to learn the basics to code C, while PHP can hide a bit of that from you (a good thing, in my opinion).
Posted: Mon Jul 31, 2006 6:38 pm
by panic!
I do agree with you but it's nothing that can't be learned in a week or two, I think pointers are the main fundimental that people have trouble with to begin with (I speak from personal experience, I couldn't get my head round them for ages).
Posted: Mon Jul 31, 2006 7:35 pm
by RobertGonzalez
robincard wrote:if you can code php...you can code C, I'm come from a C background and found the two very similar.
I'd agree with the inverse. But I still have a heck of a time wrapping my mind around C. PHP was a snap for some reason, but C seems rather daunting.
Posted: Mon Jul 31, 2006 8:42 pm
by bg
robincard wrote:if you can code php...you can code C, I'm come from a C background and found the two very similar.
Ehhh... no. PHP is loosely typed, whereas c is not. PHP handles memory allocation for you. The only thing at all similar is the basic syntax.
Posted: Mon Jul 31, 2006 8:47 pm
by alex.barylski
C and PHP are way complete different...
I'll note some key differences, instead of just syaing there different...
C is a complex "compiled" language, getting code to complie without errors on anything but trivial applications can be tricky, not to mention cross platform tests, etc...
On large applications you will encounter namespace collisions, which is partly why C++ was introduced...
Compiler and linker errors, depending on compiler aren't very clear, it's years of experience which let you discover and correct bugs properly not a few weeks reading C.
C is vastly more powerful and flexible. You can program complete OS's (minus a bit of ASM) device drivers, COM components, applications, etc...
PHP is limited to basically web applications, which it does excellently, which is why I use it instead of C (which is how I started programming server side scripts in).
C requires understanding of advanced memeory techniques....
Whats the difference between a heap or a stack? In PHP it's ZE memory allocaiton routines and garbage collection take care of this for you...
Do you have the diligence to check every pointer? Cause a bad pointer in C will almost always be a bad thing...
What's the difference between a pointer and a reference?
You want to include a third pary library, but are only given an *.lib file, where do you start?
Programming a GUI in straight C is killer...it's why frameworks like MFC, OWL, wxWidgets, etc were introduced...
The point is, C is a massively more complex language than PHP, PHP is a *very* high level language whereas C is often refered to a low level language...as in you have more direct contorl over a computer, second only to ASM...
I should have read more, but how did this even start? Such a silly disscussion...as clearly anyone who is competent in C would agree it's much more difficult than PHP...
Especially for building applications...
Fibonacci number sequence generators you program in Collage, etc...are only scraping the roof of the basics...so they don't count and it doesn't qualify you as a C developer...
Posted: Sun Sep 03, 2006 5:03 am
by ngungo
Hi Tim,
I just received your message through paypal. My brief reply is NO, I haven't got my problem solved. Since then I searched and read more about php extension, bought
this book and read through but unable to make sense out of it. Sorry me, huh!
I really need help but I also know that is all you can help. I appreciate.
ngungo