Last active
August 29, 2015 14:07
-
-
Save polonskiy/0e1a289a6cf55a89ecdc to your computer and use it in GitHub Desktop.
echo servers in php and go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$server = stream_socket_server('tcp://127.0.0.1:8000'); | |
while (true) { | |
$client = stream_socket_accept($server, -1); | |
if (pcntl_fork() === 0) { | |
stream_copy_to_stream($client, $client); | |
die; | |
} | |
fclose($client); | |
while (pcntl_wait($status, WNOHANG)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"net" | |
) | |
func main() { | |
server, _ := net.Listen("tcp", "127.0.0.1:8000") | |
for { | |
client, _ := server.Accept() | |
go func() { | |
io.Copy(client, client) | |
client.Close() | |
}() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"net" | |
) | |
func main() { | |
server, _ := net.Listen("tcp", "127.0.0.1:8000") | |
for { | |
client, _ := server.Accept() | |
io.Copy(client, client) | |
client.Close() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$server = stream_socket_server('tcp://127.0.0.1:8000'); | |
while (true) { | |
$client = stream_socket_accept($server, -1); | |
stream_copy_to_stream($client, $client); | |
fclose($client); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment