php .NET and ANSI C

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

php .NET and ANSI C

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That is a great tutorial. Makes me want to go out and learn C so I can write an extension.
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post 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.
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post 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."
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'd bet if you threw him some money at that email address through Paypal it would work...
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Post by panic! »

if you can code php...you can code C, I'm come from a C background and found the two very similar.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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).
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Post 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).
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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...
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post by ngungo »

timvw wrote: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...
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
Post Reply