DEV Community

Cover image for Server Side: Dart vs. PHP
Julian Finkler
Julian Finkler

Posted on

Server Side: Dart vs. PHP

I'm courious, please comment 🙂

If you've to choose between Dart and PHP:

Which one do you prefer for server side programming?:
...

Why?:
...

Why not (Dart|PHP)?:
...

Top comments (6)

Collapse
 
kyorohiro profile image
kyorohiro (kiyohiro kawamura) • Edited

If for a small job, I choice PHP.
Because, PHP has many developer, and useful framework for web.We can do fast develop and fast release at PHP.

If for my project, I choice Dart.
Because, Dart is easy to develop web service by strong type and smart editors and IDE.

Collapse
 
sayiidaaaaa profile image
Sayida Humaira

where i can find good tutorial for dart lang? thank you :)

Collapse
 
fredbouchery profile image
Frédéric Bouchery • Edited

PHP is designed for app on server side, and Dart for app on client side. So, use both.

Collapse
 
devtronic profile image
Julian Finkler • 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
 
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
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. :)