15. Networks

Created Monday 08 September 2014

15.1. Sockets

15.1.1. Sockets are files

resource fsockopen ( string target, int port [, int error_number [, string error_string [, float timeout]]])

<?php
$fp = fsockopen("slashdot.org", 80);
if ($fp) {
fwrite($fp, "GET / HTTP/1.1\r\nHOST: slashdot.org\r\n\r\n");
while (!feof($fp)) {
print fread($fp, 256);
}
fclose($fp);
} else {
print "Fatal error\n";
}
?>

15.1.2. Making a simple search engine

15.1.3. Sockets aren't all about HTTP

15.1.4. Sockets can be servers

<?php
$socket = @socket_create_listen("12345");

if (!$socket) {
print "Failed to create socket!\n";
exit;
}

while (true) {
$client = socket_accept($socket);
$welcome = "\nWelcome to the Amazing ROT13 Machine.\nType '!close' to close this connection, or type '!halt' to halt the server.\n";
socket_write($client, $welcome);

while (true) {
$input = trim(socket_read ($client, 256));
if ($input == '!close') {
break;
}

if ($input == '!halt') {
socket_close ($client);
break 2;
}

$output = str_rot13($input) . "\n";
socket_write($client, $output);
print "Them: $input, Us: $output\n";
}

socket_close ($client);
}

socket_close ($socket);
?>

telnet localhost 12345

15.1.5. Sockets can be powerful

15.2. Domain resolution functions

15.3. Host and IP resolution

15.4. HTTP

15.4.1. Sending custom headers

15.4.2. Reading queued headers

15.4.3. Authentication over HTTP

15.4.4. Dynamic authentication

15.5. Sending mail

15.5.1. MIME types

15.5.2. Easier mail sending with PEAR::Mail

15.5.3. Sending mixed-type messages with PEAR::Mail_Mime

15.5.4. Sending attachments (at last!)

15.6. Reading mail

15.6.1. Opening a mailbox

15.6.2. Reading message information

15.6.3. Reading message contents

15.7. Dealing with MIME-encoded messages

15.8. Mail management

15.9. Transferring files over FTP

15.9.1. Other helpful FTP functions

15.10. Curl

15.10.1. Installing Curl

15.10.2. Your first Curl scripts

15.10.3. The abridged list of Curl options

15.10.4. Debugging Curl

15.11. Custom data stream handling

15.11.1. The Morse code stream

15.12. Summary

15.13. Exercises

15.14. Further reading



Backlinks: