瀏覽代碼

Add Peachpie to PHP frameworks (#3207)

* Add simple Peachpie plain text test

* Add Peachpie to .travis.yml

* Change Peachpie website assembly name

* Add .gitignore to Peachpie tests

* Install .NET Core SDK 1.0.4 for Peachpie tests

* Add JSON encoding Peachpie test

* Add database queries Peachpie tests

* Add database updates Peachpie test

* Add MySQL to Peachpie tests prerequisities

* Add fortunes Peachpie test

* Tune up server in Peachpie tests

Remove unnecessary sessions and caching. Target netcoreapp2.0 on runtime
configuration.

* Enclose Peachpie tests in functions

* Add README.md and source_code to Peachpie tests

* Remove PHP project hack from Peachpie tests

* Simplify Peachpie setup

Remove (now unnecessary) installation of .NET Core 1.0.4 and dotnet
restore. Run the website in the Release configuration.

* cleanup and simplify fortune test

* Add missing mysql_close() to Peachpie tests

* Fix Peachpie version to 0.8.0-CI00448

* Update Peachpie version to 0.9.0-CI00687

* Fix Peachpie NuGet issues
Robert Husák 7 年之前
父節點
當前提交
0997b2b15b

+ 1 - 0
.travis.yml

@@ -142,6 +142,7 @@ env:
     - "TESTDIR=PHP/limonade"
     - "TESTDIR=PHP/lithium"
     - "TESTDIR=PHP/lumen"
+    - "TESTDIR=PHP/peachpie"
     - "TESTDIR=PHP/phalcon"
     - "TESTDIR=PHP/phalcon-micro"
     - "TESTDIR=PHP/phpixie"

+ 275 - 0
frameworks/PHP/peachpie/.gitignore

@@ -0,0 +1,275 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+**/Properties/launchSettings.json
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# TODO: Comment the next line if you want to checkin your web deploy settings
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# The packages folder can be ignored because of Package Restore
+**/packages/*
+# except build/, which is used as an MSBuild target.
+!**/packages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/packages/repositories.config
+# NuGet v3's project.json files produces more ignoreable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+node_modules/
+orleans.codegen.cs
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+*.mdf
+*.ldf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+# CodeRush
+.cr/
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config

+ 48 - 0
frameworks/PHP/peachpie/Benchmarks.sln

@@ -0,0 +1,48 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26124.0
+MinimumVisualStudioVersion = 15.0.26124.0
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Website", "Website\Website.msbuildproj", "{A271793F-72BF-429D-9EC8-83C03559CBD6}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{AF5D53C1-32B5-473F-9229-817608068701}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Debug|x64.ActiveCfg = Debug|x64
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Debug|x64.Build.0 = Debug|x64
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Debug|x86.ActiveCfg = Debug|x86
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Debug|x86.Build.0 = Debug|x86
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Release|x64.ActiveCfg = Release|x64
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Release|x64.Build.0 = Release|x64
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Release|x86.ActiveCfg = Release|x86
+		{A271793F-72BF-429D-9EC8-83C03559CBD6}.Release|x86.Build.0 = Release|x86
+		{AF5D53C1-32B5-473F-9229-817608068701}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{AF5D53C1-32B5-473F-9229-817608068701}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{AF5D53C1-32B5-473F-9229-817608068701}.Debug|x64.ActiveCfg = Debug|x64
+		{AF5D53C1-32B5-473F-9229-817608068701}.Debug|x64.Build.0 = Debug|x64
+		{AF5D53C1-32B5-473F-9229-817608068701}.Debug|x86.ActiveCfg = Debug|x86
+		{AF5D53C1-32B5-473F-9229-817608068701}.Debug|x86.Build.0 = Debug|x86
+		{AF5D53C1-32B5-473F-9229-817608068701}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{AF5D53C1-32B5-473F-9229-817608068701}.Release|Any CPU.Build.0 = Release|Any CPU
+		{AF5D53C1-32B5-473F-9229-817608068701}.Release|x64.ActiveCfg = Release|x64
+		{AF5D53C1-32B5-473F-9229-817608068701}.Release|x64.Build.0 = Release|x64
+		{AF5D53C1-32B5-473F-9229-817608068701}.Release|x86.ActiveCfg = Release|x86
+		{AF5D53C1-32B5-473F-9229-817608068701}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+EndGlobal

+ 36 - 0
frameworks/PHP/peachpie/README.md

@@ -0,0 +1,36 @@
+# Peachpie Benchmarking Test
+
+This is the [Peachpie](http://github.com/peachpiecompiler/peachpie) portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+As we want Peachpie to be comparable to the PHP Interpreter, we derived our tests from theirs with the following modifications:
+
+1. Some logic was updated to prevent warnings during verification.
+
+2. Global code was enclosed in functions. Not only is Peachpie able to optimize such code better, but it is also a common programming practice.
+
+3. Because PDO is not yet implemented in Peachpie, old-fashioned MySQL functions such as `mysql_connect()` are used. We are going to replace them by PDO eventually.
+
+4. Currently, only raw database tests without ORM are performed.
+
+## Test Sources
+
+* [JSON Serialization](./Website/json.php)
+* [Database Queries](./Website/dbraw.php)
+* [Fortunes](./Website/fortune.php)
+* [Database Updates](./Website/updateraw.php)
+* [Plaintext](./Website/plaintext.php)
+
+## Test URLs
+
+* http://localhost:8080/json.php
+* http://localhost:8080/dbraw.php
+* http://localhost:8080/dbraw.php?queries=10
+* http://localhost:8080/fortunes.php
+* http://localhost:8080/updateraw.php
+* http://localhost:8080/updateraw.php?queries=10
+* http://localhost:8080/plaintext.php
+
+## Contacts
+
+* [http://github.com/jakubmisek](Jakub Míšek) - Chief developer of Peachpie
+* [http://github.com/roberthusak](Robert Husák) - Author of this contribution

+ 32 - 0
frameworks/PHP/peachpie/Server/Program.cs

@@ -0,0 +1,32 @@
+using System;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using Peachpie.Web;
+
+namespace MyWebsite.Server
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            var host = new WebHostBuilder()
+                .UseKestrel()
+                .UseUrls("http://*:8080/")
+                .UseStartup<Startup>()
+                .Build();
+
+            host.Run();
+        }
+    }
+	
+	class Startup
+    {
+        public void Configure(IApplicationBuilder app)
+        {
+            app.UsePhp(new PhpRequestOptions(scriptAssemblyName: "Website"));
+            app.UseDefaultFiles();
+            app.UseStaticFiles();
+        }
+    }
+}

+ 20 - 0
frameworks/PHP/peachpie/Server/Server.csproj

@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp2.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.1" />
+    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.1" />
+    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
+    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" />
+    <PackageReference Include="Peachpie.NETCore.Web" Version="0.9.0-CI00687" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\Website\Website.msbuildproj" />
+  </ItemGroup>
+
+</Project>

+ 18 - 0
frameworks/PHP/peachpie/Website/Website.msbuildproj

@@ -0,0 +1,18 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Library</OutputType>
+    <TargetFramework>netstandard1.6</TargetFramework>
+	<AssemblyName>Website</AssemblyName>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <Compile Include="**/*.php" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <DotNetCliToolReference Include="Peachpie.Compiler.Tools" Version="0.9.0-CI00687" />
+    <PackageReference Include="Peachpie.NET.Sdk" Version="0.9.0-CI00687" PrivateAssets="Build" />
+  </ItemGroup>
+  
+</Project>

+ 51 - 0
frameworks/PHP/peachpie/Website/dbraw.php

@@ -0,0 +1,51 @@
+<?php
+//
+// Database Test
+//
+
+function dbraw() {
+  // Database connection (TODO: When it works, use PDO instead)
+  $link = mysql_connect('TFB-database', 'benchmarkdbuser', 'benchmarkdbpass');
+  mysql_select_db('hello_world', $link);
+
+  // Read number of queries to run from URL parameter
+  $query_count = 1;
+  $is_multi = isset($_GET['queries']);
+  if ($is_multi) {
+    $query_count = (int)$_GET['queries'];
+    if ($query_count > 500) {
+      $query_count = 500;
+    } else if ($query_count < 1) {
+      $query_count = 1;
+    }
+  }
+
+  // Create an array with the response string.
+  $arr = array();
+  $id = mt_rand(1, 10000);
+
+  // For each query, store the result set values in the response array
+  while (0 < $query_count--) {
+    $result = mysql_query("SELECT randomNumber FROM World WHERE id = $id", $link);
+
+    // Store result in array.
+    $arr[] = array('id' => $id, 'randomNumber' => mysql_result($result, 0));
+    $id = mt_rand(1, 10000);
+  }
+
+  mysql_close($link);
+
+  // Set content type
+  header("Content-type: application/json");
+
+  // Use the PHP standard JSON encoder.
+  // http://www.php.net/manual/en/function.json-encode.php
+  if ($is_multi) {
+    echo json_encode($arr);
+  } else {
+    echo json_encode($arr[0]);
+  }
+}
+
+dbraw();
+?>

+ 51 - 0
frameworks/PHP/peachpie/Website/fortune.php

@@ -0,0 +1,51 @@
+<?php
+//
+// Database Test
+//
+
+function fortune() {
+  // Database connection // TODO: use PDO once implemented
+  $link = mysql_connect('TFB-database', 'benchmarkdbuser', 'benchmarkdbpass');
+  mysql_select_db('hello_world', $link);
+    
+  // Store result in array.
+  $result = mysql_query('SELECT id, message FROM Fortune', $link);
+  $arr = array();
+  while ($row = mysql_fetch_array($result)) {
+    $arr[$row['id']] = $row['message'];
+  }
+
+  mysql_close($link);
+
+  $arr[0] = 'Additional fortune added at request time.';
+
+  asort($arr);
+  return $arr;
+}
+
+// Set content type
+header("Content-type: text/html; charset=utf-8");
+
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+<?php
+foreach ( fortune() as $id => $fortune ) {
+?>
+<tr>
+<td><?php echo htmlspecialchars($id, ENT_QUOTES, 'UTF-8'); ?></td>  
+<td><?php echo htmlspecialchars($fortune, ENT_QUOTES, 'UTF-8'); ?></td>
+</tr>
+<?php } ?>
+</table>
+</body>
+</html>

+ 21 - 0
frameworks/PHP/peachpie/Website/json.php

@@ -0,0 +1,21 @@
+<?php
+//
+// JSON Encoding Test
+//
+
+function json() {
+  // Set content type
+  header("Content-type: application/json");
+
+  // Create an array with the response string.
+  $arr = array(
+      "message" => "Hello, World!"
+  );
+
+  // Use the PHP standard JSON encoder.
+  // http://www.php.net/manual/en/function.json-encode.php
+  echo json_encode($arr);
+}
+
+json();
+?>

+ 10 - 0
frameworks/PHP/peachpie/Website/plaintext.php

@@ -0,0 +1,10 @@
+<?php
+//
+// Plaintext Test
+//
+
+// Set content type
+header("Content-type: text/plain");
+
+?>
+Hello, World!

+ 53 - 0
frameworks/PHP/peachpie/Website/updateraw.php

@@ -0,0 +1,53 @@
+<?php
+//
+// Database Test
+//
+
+function updateraw() {
+  // Database connection (TODO: When it works, use PDO instead)
+  $link = mysql_connect('TFB-database', 'benchmarkdbuser', 'benchmarkdbpass');
+  mysql_select_db('hello_world', $link);
+
+  // Read number of queries to run from URL parameter
+  $query_count = 1;
+  if (isset($_GET['queries'])) {
+    $query_count = (int)$_GET['queries'];
+    if ($query_count > 500) {
+      $query_count = 500;
+    } else if ($query_count < 1) {
+      $query_count = 1;
+    }
+  }
+
+  // Create an array with the response string.
+  $arr = array();
+  $id = mt_rand(1, 10000);
+  $randomNumber = mt_rand(1, 1000);
+
+  // For each query, store the result set values in the response array
+  while (0 < $query_count--) {
+    $result = mysql_query("SELECT randomNumber FROM World WHERE id = $id", $link);
+    
+    // Store result in array.
+    $world = array('id' => $id, 'randomNumber' => mysql_result($result, 0));
+    $world['randomNumber'] = $randomNumber;
+
+    mysql_query("UPDATE World SET randomNumber = $randomNumber WHERE id = $id", $link);
+    
+    $arr[] = $world;
+    $id = mt_rand(1, 10000);
+    $randomNumber = mt_rand(1, 10000);
+  }
+
+  mysql_close($link);
+
+  // Set content type
+  header("Content-type: application/json");
+
+  // Use the PHP standard JSON encoder.
+  // http://www.php.net/manual/en/function.json-encode.php
+  echo json_encode($arr);
+}
+
+updateraw();
+?>

+ 28 - 0
frameworks/PHP/peachpie/benchmark_config.json

@@ -0,0 +1,28 @@
+{
+  "framework": "peachpie",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json.php",
+      "plaintext_url": "/plaintext.php",
+      "db_url": "/dbraw.php",
+      "query_url": "/dbraw.php?queries=",
+      "fortune_url": "/fortune.php",
+      "update_url": "/updateraw.php?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "MySQL",
+      "framework": "None",
+      "language": "PHP",
+      "flavor": "PHP7",
+      "orm": "Raw",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Peachpie",
+      "notes": ""
+    }
+  }]
+}

+ 3 - 0
frameworks/PHP/peachpie/setup.sh

@@ -0,0 +1,3 @@
+fw_depends mysql dotnetcore
+
+dotnet run -p Server -c Release

+ 9 - 0
frameworks/PHP/peachpie/source_code

@@ -0,0 +1,9 @@
+./Benchmarks.sln
+./Server/Program.cs
+./Server/Server.csproj
+./Website/dbraw.php
+./Website/fortune.php
+./Website/json.php
+./Website/plaintext.php
+./Website/updateraw.php
+./Website/Website.msbuildproj