DEV Community

Discussion on: Server Side: Dart vs. PHP

Collapse
devtronic profile image
Julian Finkler Author • Edited

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

Sample:

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

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

  await for (HttpRequest request in server) {
    request.response.write('Hello World');
    await request.response.close();
  }
}
<?php
// 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 🙂

Collapse
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. :)

Collapse
ljfreelancer88 profile image
Eljay

How about this...

<?php
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

$server = new Swoole\HTTP\Server("127.0.0.1", 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");
});

$server->start();
Enter fullscreen mode Exit fullscreen mode