Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Peachpie – Open Source PHP Compiler to .NET and WordPress under ASP.NET Core (hanselman.com)
86 points by pchp on July 28, 2017 | hide | past | favorite | 35 comments


This has nothing to do directly with this blog post, but just wanted to say that Scott Hanselman is probably the best that could have happened to .NET of all things. Better than Linq and async/await together. He's an amazing speaker and his blog is a great resource for everything around .NET. Can highly recommend to watch and follow this guy!


He also comes across as very humble on his Hanselminutes podcast. Great guy.


Agreed. He and Scott Guthrie used to make an amazing 1-2 punch when they were both working in the ASP.NET area of Microsoft.


Unfortunately Scott is all cloud and Azure these days and very little programming spirit is left.


This is really about Peachpie, an open source PHP to .NET compiler. (Edit: the title has now been updated) From the comments on the article, here's a set of benchmarks showing Peachpie with a significant performance advantage over PHP 7 in a number of benchmarks: http://www.peachpie.io/benchmarks. That said, it's still hard to get excited about PHP.


Disclaimer: PHP core dev.

Be careful with microbenchmarks. From my experience, there tends to be very little correlation between performance improvements on microbenchmarks and real applications. If you improve performance on the microbench suite by a factor of two, you definitely will not get a factor of two on real applications -- more likely, it will be something like 2%.

Basically, if the benchmark is not testing end-to-end performance on Wordpress (or similar), then it's a useless benchmark.


The classic example of this would be that, before PHP 7, Zend spent a lot of effort trying to make PHP use JIT. It improved the results on microbenchmarks a lot, but made negligible difference to real-world code, IIRC.


Good point. In case of Peachpie microbenchmarks - that time it was the only pieces code that could be compiled ... We'll try to update benchmarks for more complex solutions.


We have a huge PHP codebase we may be interested to bring into the .NET world. I have looked at Peachpie but I wonder how well it works in the real world and what the long term prospects are.

Has anybody used it? The PHP code is full of questionable code which somehow works in PHP but I am not sure if it's possible to map PHP's behavior into .NET..


Disclaimer - Peachpie dev. Some of the weird PHP constructs will never work - by purpose. In such case it will be reported in compile-time or at least in run-time. However, there is always a way of slightly changing the original code to make it running on .NET.


What PHP version is Peachpie targeting?


From this:

https://github.com/peachpiecompiler/peachpie/wiki/Peachpie-R...

Looks like PHP 5.4 and 7.1 roadmap goals have been achieved.

Though http://www.peachpie.io/about references Phalanger as the inspiration which apparently got as far as PHP 5.6.

There's also compatibility page that looks useful:

https://github.com/peachpiecompiler/peachpie/wiki/Compatibil...


Do you happen to have any examples?


For example one CLR limitation - `yield` cannot be in a catch block. Two workarounds - compiler can generate a crazy state machine or user can just move the PHP yield outside the catch.

Error handling is a big issue - in PHP every notice and warning can be handled in user code, in .NET we use Debug Assertions or exceptions. But .NET has threads and async which shares one thread by more requests, so in case of error we just don't know what request has to handle the error. We would have to pass some request context object to every function in runtime in order to be able to let the correct request's error_handler to handle the error - or we just assume warnings and errors should not happen and crash when it does.

Garbage Collection - for performance reasons (and sanity) we let .NET GC to do its job. But unlike PHP's GC it is undeterministic and does its job on a different thread. For now, __destruct is not handled in Peachpie yet cause there are more ways on how to simulate PHPs behavior.

Changing existing closure's $this to anything - well.. besides it would make type analysis useless, it totaly violates strong .NET method access checks.


__destruct is not called when the reference count goes to 0? This is one of the (few) features I think PHP does better than C#.


And one of the features caused memory leaking in PHP for a decade. .NET has real garbage collection, we can take advantage of it.


They did get WordPress at least sort of running on it. That wasn't possible with the first releases of hhvm, so it says something.


It's says they actually get WordPress running before releasing it. Not that I want to undermine project achievements, but WordPress likely going to work even on PHP 5.2.x that almost 10 years old.


My point was that WordPress is a large codebase and exercises a fair amount of php syntax and built-ins.


5.2.x is old, but that doesn't mean it's simple or easier to implement.


You're right, 7.0 for example deprecates/removes some dirty practices that are hard to implement in .NET


'Sort of running' and stable enough to deploy into production are different things. I really want this to work but I am a little nervous about committing to it.


It was running with modifications at the time, but now runs unmodified. I suggest to get in touch with the team to discuss your specific case at info at iolevel dot com.


Probably a good idea. For us this would be huge if it worked but it's pretty scary...


The previous version of Peachpie, Phalanger, had several clients with huge codebases who successfully used it to migrate their apps or interoperate with C#. Peachpie works the same way.


Another interesting option is TaguaVM, whose lead developer is now employed by Automattic (the company behind WordPress). More information here: https://symfony.fi/entry/exotic-php-implementations-hippyvm-...


Glad Scott noticed this. It's definitely appealing (at least in theory) for people worried about self-hosted WordPress security.

Most recent HN discussion dug into the tech and also the rationale behind transitioning in either direction: https://news.ycombinator.com/item?id=13753445 (404 points/164 comments/Feb 2017)


I believe the edge cases in this would make you wish you never heard of it.


I'm trying to find a use case for this. A .NET to php decompiler may be more useful at this point in time.


To me it seems similar to running Ruby on the JVM (JRuby). Perhaps you like php but have a lot of .net code to interop with. I bet writing business logic in C# and web tier code in php could possibly be a satisfying experience.


A dotNet asp.net (Webforms, etc) to PHP compiler would be more useful.

Now that asp.net is end of life, these sad people are looking for ways to migrate their aging asp and asp.net code base to elsewhere. The only supported option is the incompatible new asp.net core on dotNet core - out of the jungle into the jungle.


Microsoft has been steadfast that it will support the .net 4.x for foreseeable future and improvements and newer versions will come, given that 4.7 is on the way, I see no grounds for the claim webforms are being deprecated, the guidance has been MVC is the recommended solution, but WebForms were always supported.

It would be helpful if you can provide some source for this.


What would be great would be a decompiler that could port .net windows application code to http://gtk.php.net


> asp.net is end of life

Even Silverlight is not officially dead until 2021 so I'm not sure I'm clear on your terminology (vs. https://support.microsoft.com/help/17455 ).

Just for fun I dug up the "Mainstream Support End Date" for ASP.NET on .NET 4.5.2: 10/9/2018.

--

Starting from https://www.asp.net/support

Many parts of ASP.NET are a part of the Microsoft .NET Framework, these include ASP.NET Web Forms, Controls, Modules, Handlers and more. For more information see .NET Platform Support.

Then at https://www.microsoft.com/net/support

The Support Lifecycle information for all versions of .NET Framework can be seen on the Microsoft Product Lifecycle site.

Then at https://support.microsoft.com/en-us/lifecycle/search?alpha=....

For more information, please visit the .NET Framework Support Lifecycle Policy FAQ.

Then at https://support.microsoft.com/help/17455

Support for .NET 4.5.2 follows the lifecycle policy of the parent operating system. It is supported as a Windows component on the latest required operating system update for Windows Vista SP2, Windows 7 SP1, Windows Server 2008 SP2, Windows Server 2008 R2 SP1, Windows 8.1 Update, Windows Server 2012, and Windows Server 2012 R2.

Then at https://support.microsoft.com/en-us/lifecycle/search?alpha=W...

Products Released: Windows Server 2012 R2 Standard

Lifecycle Start Date: 11/25/2013

Mainstream Support End Date: 10/9/2018

Extended Support End Date: 10/10/2023

Service Pack Support End Date: [empty]

Notes: Mainstream and Extended support for this product has been extended to provide customers with the standard lifecycle transition timeline. For up to 6 years of additional support beyond Extended Support, please see the Premium Assurance website.


.NET 4.7 shipped earlier this year and includes Web Forms support. Looking at the support lifecycle page, I can see how the order of answers calling out .NET 4.5.2 at the top might be confusing. The last answer on that page ( What is the Lifecycle Policy for the different versions of the .NET Framework?) is the one I think you want - it indicates that .NET Framework 4.7 ships with Windows Server 2016 and Windows 10 CU (1703), which pushes you out to 2022 (minimum, every release keeps resetting the clock) for Mainstream Support.

[disclaimer: Microsoft employee, .NET Foundation staff]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: