DEV Community

Discussion on: Server Side: Dart vs. PHP

devtronic profile image
Julian Finkler Author • Edited

From a performance perspective on server side, Dart is ahead of PHP:


wrk http://localhost:1337 -c 8 -d 60 -t 8
/// Dart
import 'dart:io';

Future main() async {
  var server = await HttpServer.bind(
  print('Listening on localhost:${server.port}');

  await for (HttpRequest request in server) {
    request.response.write('Hello World');
    await request.response.close();
// PHP //  php -S localhost:1337
header('Content-Type: text/plain');

echo "Hello World";
$ php --version
PHP 7.3.11 (cli) (built: Feb 29 2020 02:50:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.7.0, Copyright (c) 2002-2019, by Derick Rethans
$ dart --version
Dart VM version: 2.7.2 (Mon Mar 23 22:11:27 2020 +0100) on "macos_x64"

Looks very interesting, I think I should give it a try 🙂

fredbouchery profile image
Frédéric Bouchery

yes, but PHP is more simple (just 2 lines), so it's better for newbies, simple to edit, to maintain, etc. :)

ljfreelancer88 profile image

How about this...

use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

$server = new Swoole\HTTP\Server("", 9501);

$server->on("start", function (Server $server) {
    echo "Awesomeness of PHP has been initialized\n";

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello Philippines!\n");

Enter fullscreen mode Exit fullscreen mode