. Net Core Development Log--peachpie

Source: Internet
Author: User
Tags dotnet

The. NET core ecosystem is becoming more and more powerful as the power of the open source community continues to grow, and sometimes interesting projects such as Peachpie, which make PHP's code migration to. Net core projects, become possible.

It's easier to understand the features from the start by creating a simple starter program.

First install the Peachpie template:

dotnet new -i Peachpie.Templates::*

Then create the project:

dotnet new web -lang PHP -o helloPHP

Then switch the directory to the server folder to run the program:

cd Serverdotnet run

Finally access the HTTP://LOCALHOST:5004/via the browser:

The peachpie mechanism is simple, compiling PHP files into the DLL files of the. NET platform, which can be called by other programs as normal. NET code libraries.

It consists of three parts:

    • Compiler (Peach.exe or PEACHPIE.NET.SDK) to compile the PHP file into a. NET Assembly
    • Runtime (Peachpie.Runtime.dll), the functionality required for the provider to run
    • Code base (Peachpie.Library.dll), functions that contain PHP, classes, and other implementations

Go back to the beginning of the entry code to explore, you can find that the key point is in the website directory in the Website.msbuildproj file:

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>    <OutputType>Library</OutputType>    <TargetFramework>netstandard2.0</TargetFramework>    <AssemblyName>helloPHP</AssemblyName>  </PropertyGroup>  <ItemGroup>    <Compile Include="**/*.php" />  </ItemGroup>  <ItemGroup>    <DotNetCliToolReference Include="Peachpie.Compiler.Tools" Version="0.9.0-*" />    <PackageReference Include="Peachpie.NET.Sdk" Version="0.9.0-*" PrivateAssets="Build" />  </ItemGroup></Project>

With both Peachpie.Compiler.Tools and PEACHPIE.NET.SDK, all PHP files, including index.php files, will eventually be compiled into a DLL file.

It is also very simple to use this DLL file in the Configure method of the Startup class:

app.UsePhp(new PhpRequestOptions(scriptAssemblyName: "helloPHP"));

The PHP site that runs in ASP.

The Peachpie project is still in the development phase, but does not affect its ability to do some amazing work, for example, its official website is built on WordPress, but has been compiled by Peachpie to run in ASP. You will never expect this website to be written in PHP by the following diagram:

More detailed information about this can be found in its blog.

If you're interested in migrating PHP code to the. NET platform, you can access its repository on GitHub, which is great if it can be a building block.

. Net Core Development Log--peachpie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.