Complete the code to print a message in PHP.
<?php
echo [1];
?>In PHP, strings must be enclosed in quotes when using echo.
Complete the code to start a PHP built-in server on port 8000.
php -S [1]The built-in PHP server commonly runs on localhost:8000 by default.
Fix the error in the PHP code that tries to keep a long-running server alive.
<?php while (true) { [1]("Server running...\n"); sleep(5); } ?>
In PHP, echo is used to output text. console.log is JavaScript and will cause an error.
Fill both blanks to create a PHP script that listens on port 8080 and outputs a response.
<?php $address = '127.0.0.1'; $port = [1]; $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_bind($socket, $address, $port); socket_listen($socket); $client = socket_accept($socket); socket_write($client, [2]); socket_close($client); socket_close($socket); ?>
Port 8080 is commonly used for testing servers. The message must be a string in quotes.
Fill all three blanks to create a PHP script that accepts a connection, reads data, and sends a response.
<?php $address = '0.0.0.0'; $port = [1]; $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_bind($socket, $address, $port); socket_listen($socket); $client = socket_accept($socket); $data = socket_read($client, [2]); socket_write($client, [3]); socket_close($client); socket_close($socket); ?>
Port 9000 is a common test port. Reading 1024 bytes is typical. The response must be a quoted string.