Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Phalanger: PHP .NET compiler revealed

Download

Right click “Save as…”

Tomas Matousek and Ladislav Prosek talk about their PHP .NET compiler, Phalanger. These guys don't work at Microsoft, Charles Torre ran into them at a recent CLR compiler lab held on Microsoft's main campus. Very cool stuff. You can learn more on their Web site.

Follow the Discussion

  • ZippyVZippyV Fired Up

    Did those guys also make it possible to create PHP files in Visual Studio.net (with statement completion, intellimenus)?

  • rhmrhm
    I see. I was wondering what the point of it was - I mean it has the disadvantage of an old-fashioned execution model (php) with none of the advantage of php (being able to run on a free OS). If you're going to restrict yourself to running on Windows you'd be mad not to ASP.NET. And if you had a whole heap of PHP code you wanted to run you could just use PHP anyway which is available for Windows. I suppose being able to run PHP code faster could be useful to some people though.

    I thought Zend was a compiler of sorts but I guess it interprets the bytecode it generates (like early JVMs) so it's still not as fast as a CLR based system.

    I like the way people approach the CLR with "I wondered if it was possible to for it to run a dynamic language" - I've seen that from the developers of quite a few different projects before. Of course it's possible for the CLR to run any language at some level as it is a turing-complete machine even in verifyable mode. To run a dynamic langauge just means the compiler just has to throw out a lot more instructions to handle things like late binding and run-time type conversions. OK, the CLR isn't ideally suited to all langauges which means a langauge-specific runtime like most LISP implementation use would be faster, but the possibility to target the CLR is there for any language.
  • CharlesCharles Welcome Change

    Compiling it to managed means that you can interoperate with other managed languages really naturally. So, you can take a PHP project and add new "modules" to it that you write in, say, C#, then import the C# dll into your Phalanger project, and compile.

    So, it's more than just performance (not to mention security), but, you are right, it was kind of a "let's see if we can do this" kind of thing (which many school projects are, initially) and they did! Smart kids (well, they look like kids to me).

    C

  • CharlesCharles Welcome Change
    Nope. They made it possible to take existing PHP code (minus the unmanaged extensions, of course) and compile it to IL. The resulting code is Jitted and run on the managed heap. And it runs faster than the interpreted original. Why? Cuz it's compiled not interpeted.

    Check out their site and ask them questions and give them feedback!

    EDIT: From the authors' site:

    Our integration introduces the PHP language into the VS.NET in a specific project type supporting syntax highlighting and compilation. PHP files are compiled to .NET Framework executables and can be executed and even traced from the VS.NET environment using the generated debug information.

    To make script development and debugging more comfortable, the IntelliSense support for PHP projects and direct PHP variable insight may be added in future versions but this is not a priority for the current project. The VS.NET integration is rather some kind of add-on to the Phalanger.


    C
  • PerfectPhasePerfectPhase "This is not war, this is pest control!" - Dalek to Cyberman
    Haven't had time to watch all the videos yet, but is it possible to debug a php page in VS the same way you would an ASP.NET page?

    Stephen
  • rjdohnertrjdohnert You will never know success until you know failure
    Cool stuff, how long do you think it will take the mono guys to get this working with their stack.  I heard Miguel and Nat look at Channel 9 quite frequently.  Cool stuff though, they looked a little nervous but that happens on camera a lot if you arent used to it.  This could be used to help migrations from Linux or UNIX to Windows as well as several other uses.
  • rasxrasx Emperor of String.Empty
    It would be really, really great to generate some kind of binary that Apache servers can use running PHP. So we can build and test on our Windows box and "publish" to a non-IIS server!
  • CharlesCharles Welcome Change
    I can't talk about "Mono" but I can talk about the fact that Whidbey enables the emitting of pure IL from MC++ compilation...

    C
  • CharlesCharles Welcome Change
    rhm wrote:
    Of course it's possible for the CLR to run any language at some level as it is a turing-complete machine even in verifyable mode. 


    ?
  • Haven't had the chance to watch the video yet, but is it related in any way to PHP# which I believe got started 3 years ago but didn't get too far ?

    There is also another project called IronPHP which is still in the early stages.

    Looks like cool stuff though, can't wait to see the video at lunchtime.
  • Wow. I did know that ASP pages are somewhat faster than their PHP equivalent and that ASP.NET rocks, but the difference between pages compiled with Phalanger and regular PHP/PHP+Zend pages are impressive!
  • Hi, I'm the guy on the right (the one who looks like falling asleep Wink

    Just wanted to add that it's not just Tomas and me who worked on Phalanger - the impression you might get watching the video. Our team consists of six people (all of us are students) and I would like to name the other four that could not attend the Whidbey Compiler Lab. It's:

    Jan Benda
    Martin Maly
    Pavel Novak
    Vaclav Novak

    Rossj wrote:
    Haven't had the chance to watch the video yet, but is it related in any way to PHP# which I believe got started 3 years ago but didn't get too far ?

    There is also another project called IronPHP which is still in the early stages.


    No, it's not related to neither of these projects.
  • TMTM
    Hi everybody!
    As one of that guys who you are speaking about here Smiley I would like to answer some questions and I'm starting with this one:

    ZippyV wrote:

    Did those guys also make it possible to create PHP files in Visual Studio.net (with statement completion, intellimenus)?



    We made a simple integration to VS2003. It includes syntax highlighting, syntax checking, a simple PHP project where files can be stored and which can be compiled (by F5) and debugged (experimental feature that sometimes doesn't work well). IntelliSense and code completion and other cool features of VS are not supported yet. We are working on integration to Whidbey which is much easier to program because it can be written in C#. Nonetheless, we focus more to the compiler and run-time than to the integration to VS.



  • Cool. It is quite an impressive feat even so.

    One thing I would ask, was the fact that you could get the source code to PHP and therefore how it worked internally a factor in your choice of PHP over any other scripting language?  I guess I am looking for some sort of Open Source helped us to do what we wanted sort of statement Wink
  • TMTM
    PerfectPhase wrote:
    Haven't had time to watch all the videos yet, but is it possible to debug a php page in VS the same way you would an ASP.NET page?

    Stephen


    No it isn't yet. As I have written in the previous post a simple debugging is available nowadays. Debugging of web applications doesn't work now. We know that it would be very useful so we are planing to do it in our new integration package targeting Whidbey and maybe we will upgrade also VS2003 package.
  • TMTM
    rjdohnert wrote:
    Cool stuff, how long do you think it will take the mono guys to get this working with their stack.  I heard Miguel and Nat look at Channel 9 quite frequently.  Cool stuff though, they looked a little nervous but that happens on camera a lot if you arent used to it.  This could be used to help migrations from Linux or UNIX to Windows as well as several other uses.


    We plan to migrate to .NET Framework 2.0 soon  which will enable us also to bring Phalanger to Mono. Why? Because we use MC++ for parser implementation (there is no Bison implementation which produces C# code as far as we know - if you know about some which works perfectly let us know, please). And MC++ compiler is not avaiable on Mono yet. We will rewrite our parser to C++/CLI producing pure IL which will, we hope, enable Phalanger managed binaries to be working on Mono (I think there is also a support for ASP.NET on Mono). Of course, native extensions shipped with PHP will not work there. Only those extension which we implement (or someone else does - anybody can add his or her functionality to Phalanger clas library).
  • Rossj wrote:
    One thing I would ask, was the fact that you could get the source code to PHP and therefore how it worked internally a factor in your choice of PHP over any other scripting language?  I guess I am looking for some sort of Open Source helped us to do what we wanted sort of statement


    We had to browse through the sources of PHP quite often, but only because of the lack of documentation. If PHP had some kind of language specification, the Zend API was well documented and so on, we would have never felt a need for the sources. So yes, Open Source helped us, but we would probably prefer closed source + good documentation instead.
  • TM wrote:
    (there is no Bison implementation which produces C# code as far as we know - if you know about some which works perfectly let us know, please).


    I believe the Mono guys ported Jay (Java sort of bison which uses same syntax) to produce CS and written in CS. Unfortunately it is GPL.
  • rhm wrote:
    I thought Zend was a compiler of sorts but I guess it interprets the bytecode it generates (like early JVMs) so it's still not as fast as a CLR based system.


    As far as I know, the ZPS (and other accelerators) are rather some kind of cache. They keep an internal representation of the code in memory, so they do not have to go through the parsing stage when the page is requested again. Actually it might be viewed as a bytecode but it's still interpreted.

    rhm wrote:
    Of course it's possible for the CLR to run any language at some level as it is a turing-complete machine even in verifyable mode. To run a dynamic langauge just means the compiler just has to throw out a lot more instructions to handle things like late binding and run-time type conversions.


    Yes. The challenge is to identify which dynamic features are really dynamic (and also the contexts in which they are dynamic) and devise sophisticated optimizations. For example, if you only use reflection and compile every function invocation as a call to Type.InvokeMember, you would end up with a very slow code.
  • Phalanger guys "You take the code that you wrote for original php. You compile it and you dont have to edit a single line, It Just Works"

    So if this small grp of students achieved this, what prevents VB6 guys doing the same Wink Ok this was a pure troll Wink

    As they mention, there will be some additional stuff to be done should you want to call a .NET method that takes generic type from PHP..

    So essentially it is quite understandable why having pure VB6 in .NET just doesn't make that much sense.

  • There is no excuse not to use C# in new development, and use VB 6.0 without support...when necessary.  Nobody's breaking VB6.0 at this point.

    This from someone who's done a lot of VBA coding recently.  And C#...

    Ay...
  • VB6 will be a body sooner or later.Just accept that fact.
    Anyway,phalanger is really cool.what's IBM and ZEND thinking about?
  • You can try http://www.jcxsoftware.com for integration between Php and Visual Studio .Net
  • ladislav & TM (and rest of the team): grat job!

    I would suggest to give this compiler free also for comercial use. It seems that this is importamt :O)
  • TMTM
    radek tereszczuk wrote:
    ladislav & TM (and rest of the team): grat job!

    I would suggest to give this compiler free also for comercial use. It seems that this is importamt )


    It already is. See the license http://php-compiler.net/License.htm.
  • very nice !


  • NrpNrp

    What an outstanding video and project, well done.

    Everything I have seen and tested tonight (just the basics) it has worked like a charm.  Tomorrow I am going to attempt porting an old application that is still running on a production server.

    One negative thing I did notice though is the lack of the ability to call any .NET function straight from Phalanger.  Although I know you do not want to change the php syntax, it should be considered as an option.  From my point of view I think it is important that Phalanger runs unmodified php but it is not important that php runs unmodified Phalanger.

    Also another treasured feature of .NET is output caching for web pages and especially user controls and I would LOVE to see a similar form caching available for Phalanger.

    Once again, great work guys.

  • TMTM
    Nrp wrote:

    What an outstanding video and project, well done.

    Everything I have seen and tested tonight (just the basics) it has worked like a charm.  Tomorrow I am going to attempt porting an old application that is still running on a production server.



    Hi!
    Thanks. Well, there are some bugs. We will release a bug fix in a couple of days. So maybe it will be better for you to wait until then.

    Nrp wrote:


    One negative thing I did notice though is the lack of the ability to call any .NET function straight from Phalanger.  Although I know you do not want to change the php syntax, it should be considered as an option.  From my point of view I think it is important that Phalanger runs unmodified php but it is not important that php runs unmodified Phalanger.



    You are absolutely right. We know about this limitation and we plan to enable that. Grammar needn't to be changed to do that. But it's a lot of work so it will take some time.

    For now, there is a workaround. You can add your own PHP functions written in C# (a kind of mediators) to class library as you will see if you download source code of the Phalanger Class Library. There is an opportunity to add assemblies of your own to the class library assembly set provided they follow the same code style as the Class Library. The process of extending class library is not well documented now, however we work in the doc.

    Nrp wrote:


    Also another treasured feature of .NET is output caching for web pages and especially user controls and I would LOVE to see a similar form caching available for Phalanger.

    Once again, great work guys.



    We will consider this suggestion. Thanks.


Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.