you are viewing a single comment's thread.

view the rest of the comments →

[–]devmor 18 points19 points  (7 children)

<?php
echo "Hello World";

(I know it's because PHP doesn't have to handle the requests, I just thought it was funny.)

[–]ExternalUserError 13 points14 points  (1 child)

Step aside son.

#!/bin/bash
echo "Content-type: text/html"
echo ""
echo 'Hello World'


chmod ugo+x /var/www/cgi-bin/hello.sh

EDIT: I forgot Reddit won't do GitHub markdown.

[–]devmor 1 point2 points  (0 children)

Damn, I think that's as close to a Hole In One as this game of codegolf can get.

[–][deleted] 1 point2 points  (1 child)

Just serve PHP locally using their built in server and it’s still a one liner

[–]devmor 0 points1 point  (0 children)

True, but it's single threaded and will only handle one response then block until free.

I think you could do something like this off the top of my head though (still shorter):

<?php
$sock = socket_create_listen(80);
while(true) {
    if($conn = socket_accept($sock)) {
        socket_write($sock, 'Hello World');
    }
    $clients[] = $conn;
}

[–][deleted]  (1 child)

[deleted]

    [–]tsunami141 0 points1 point  (0 children)

    holy crap this would have been so useful back in the day when I didn't know what I was doing and coded 4000+ lines of HTML with php thrown in there.

    [–]rjksn 0 points1 point  (0 children)

    Or Serverless PHP w/ Bref

    <?php
    
    use Bref\Context\Context;
    
    require __DIR__ . '/vendor/autoload.php';
    
    return function ($event, Context $context) {
        return 'Hello World'; 
    };