PHP Classes

File: config/serve.php

Recommend this page to a friend!
  Packages of Amirreza Ebrahimi   URL Shortener Application   config/serve.php   Download  
File: config/serve.php
Role: Example script
Content type: text/plain
Description: Example script
Class: URL Shortener Application
Application to create and redirect short URLs
Author: By
Last change:
Date: 7 months ago
Size: 797 bytes
 

Contents

Class file image Download
<?php

# Server settings
$serv = (object)[
   
'host' => 'localhost', # The IP address where the server will run
   
'port' => '8181' # The port number for the server
];

# Construct the command to start the PHP built-in server
$command = sprintf("php -S %s:%d", $serv->host, $serv->port);

# Execute the command
try {
   
exec($command, $output, $returnVar);
   
# Check the result of the command execution

   
if ($returnVar === 0) {
       
# If the command was successful, output the server URL
       
echo "Server started at http://{$serv->host}:{$serv->port}\n";
    } else {
       
# If the command failed, output the error messages
       
throw new Exception("Failed to start server : http://{$serv->host}:{$serv->port}\n");
    }
} catch (
Exception $e) {
    echo
$e->getMessage();
}