0

How to use a php extension like mcrypt? My first thought was to find mcrypt.php and simply include it (context.Include("mcrypt.php", false);), but of course that doesn't exist since it is written in C.
I was reading over Writing compiled PHP extensions in PHP post from the blog but that seems to be about creating your own extension for use in .net. But maybe Im wrong considering this statement: "Implement Phalanger extension in PHP langage. When you take your PHP library and compile it using Phalanger, the result is DLL working as any other extension" But even still phpc (phalanger php compiler) is not going to compile c code as far as I know though I haven't tried.

these are the calls my php class is trying to make: mcrypt_module_open mcrypt_enc_get_key_size mcrypt_enc_get_block_size

owen gerig
  • 6,165
  • 6
  • 52
  • 91
  • .NET has its own set of crypto libraries. Can't you use those? – NullUserException Oct 16 '12 at 20:19
  • trying not to, the php classes im trying to use are provided by a vendor. So im trying to keep those intact and have my front end asp.net. Plus learning about this phalanger stuff is fun. in the end if it cant be done thats what i will have to do – owen gerig Oct 16 '12 at 20:49

2 Answers2

1

mcrypt is not yet reimplemented as managed Phalanger extension ... if you know some opensource alternative I can help with porting to Phalanger Extension.

For now, you can use native alternative (so you would have to run in x86). Simply open your .config (web.config for web app, or create app.config for desktop app), and add following

<phpNet>
    <classLibrary>
        <add assembly="php_mcrypt.mng, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4ef6ed87c53048a3" section="mcrypt" />
Jakub Míšek
  • 1,036
  • 9
  • 12
  • Thanks, this eventually got me to where I needed to go. Read my answer below if you want further details. I would mark this as the answer however there where some steps left out and I think myn might be easier for future readers. – owen gerig Oct 18 '12 at 17:48
1

Jakub Míšek's answer is definitely right and if this post helps you please vote him up as well. However I wanted to simplify what he said as his advice still took me some time to understand what he was saying. Also please Jakub if you get a chance to read this correct me if Im wrong about anything.

First thing that got me about his answer was this file

php_mcrypt.mng

mng what is that???? But after digging through their [Phalanger] svn and the files located in

C:\Program Files\Phalanger 3.0\Wrappers

I found the mcrypt file. Also with some help from the php chat room I got a clue as to what the mng was, Managed Code.

So after adding the file as a reference as well as editing the web.config file to include it (as Jakub shows)

  <phpNet>
    <classLibrary>
      <add assembly="php_mcrypt.mng, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4ef6ed87c53048a3" section="mcrypt" />
    </classLibrary>
    <scriptLibrary/>
  </phpNet>

These lines must be feeding into Phalanger to load this extension when compiling (I think/know).

After that everything seems to compile and run fine! Thanks Jakub

owen gerig
  • 6,165
  • 6
  • 52
  • 91
  • Right. Just to clarify that .mng file; Phalanger is completely in C# (managed code) - still it is needed to support some legacy PHP extensions which are in C language (native code). Phalanger comes with mechanism which generates managed code (.mng) around the native code. In this way, when configuring Phalanger, you are actually using that .mng file which internally passes calls to the native PHP extension. – Jakub Míšek Oct 07 '13 at 08:49