SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Questions about writing PHP extensions in C/C++

    Well I've been designing my own String and Array classes for my application framework, it works pretty well so far but there is a problem. With arrays it's not an issue as my class extends PHP's SplFixedArray and performance is actually better than PHP built-in array. With string however, the string object is about 3-5x slower than PHP native string.

    I've been researching into how to improve performance further, and this idea of writing PHP extension comes into my eyes. It seems that writing a PHP class in C/C++ as an extension is considerably faster than writing in PHP, it can come in handy with objects that you will likely to mass produce(string for instance). However, I still have a few questions about writing PHP extensions.

    1. How can I port a C/C++ class into PHP from application code? As I am writing a software that will be used by clients, they may install/run my script on shared hosts. Is this gonna be a problem as it probably needs to recompile PHP source code?
    2. The hacker's guide to write classes has nothing in it, no idea why. Anyone actually has a tutorial for writing PHP extensions for classes? Or is there a book/online-tutorial that describes how to write PHP extensions in details?
    http://www.php.net/manual/en/internals2.classes.php

    Id appreciate if any of you advanced/expert coders answer my questions, many thanks for just reading through it.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Hall of Famer
    How can I port a C/C++ class into PHP from application code? As I am writing a software that will be used by clients, they may install/run my script on shared hosts. Is this gonna be a problem as it probably needs to recompile PHP source code?
    If you're using a shared hosting it is highly unlikely you will be able to add custom extensions for the reason you mentioned.

    Quote Originally Posted by Hall of Famer
    The hacker's guide to write classes has nothing in it, no idea why. Anyone actually has a tutorial for writing PHP extensions for classes? Or is there a book/online-tutorial that describes how to write PHP extensions in details?
    The first thing would be to learn c. You probably won't get very far without at least intermediate/advanced understanding of c and computer science principles. All the things we take for granted in PHP like memory management aren't done so automatically in c. Not mention understanding make files and compiling which is one big pain when compared to the ease of PHP and other interpreted languages.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •