douchendan0040
2012-10-16 20:13
浏览 26

使用mcrypt与phalanger

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

图片转代码服务由CSDN问答提供 功能建议

如何使用像mcrypt这样的php扩展? 我的第一个想法是找到mcrypt.php并简单地包含它(context.Include(“mcrypt.php”,false);),但当然这不存在,因为它是用C语言编写的。
我是 阅读用PHP编写已编译的PHP扩展 博客但似乎是关于创建自己的扩展以在.net中使用。 但也许我错了考虑这句话:“在PHP语言中实现Phalanger扩展。当你使用你的PHP库并使用Phalanger进行编译时,结果是DLL像其他任何扩展一样工作” 但即使是phpc(phalanger php编译器)也不是 据我所知,尽管我还没有尝试过编译c代码。

这些是我的php类试图进行的调用: mcrypt_module_open mcrypt_enc_get_key_size mcrypt_enc_get_block_size

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douche3244 2012-10-18 17:47
    已采纳

    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

    点赞 评论
  • duanliangman5398 2012-10-16 20:55

    It's not that complicated install and use MCrypt. For *nix users PHP.net provides a source of information in this page.

    But for Windows there is not too much information.

    However it's easy too. You just have copy the file libmcrypt.dll from a PHP Binary, save it in ext directory and enable it:

    extension=php_mcrypt.dll
    

    Note: In WINDOWS environment PHP EXtensions are usually anemd as php_ so you have to rename the DLL or the PHP.INI line above.

    After that, restart Apache.

    But before you do this, check your phpinfo() first because some packages and/or distributions comes with a pre-compiled static MCrypt.

    Run it and check for with-mcrypt=static and/or MCrypt group with mcrypt support enabled

    点赞 评论
  • dongyi6845 2012-10-17 19:19

    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" />
    
    点赞 评论

相关推荐 更多相似问题