Getting started with PHPVariablesArraysFunctional ProgrammingTypesAutoloading PrimerException Handling and Error ReportingWorking with Dates and TimeSending EmailSessionsCookiesClasses and ObjectsPassword Hashing FunctionsOutput BufferingJSONSOAP ClientReflectionUsing cURL in PHPDependency InjectionXMLRegular Expressions (regexp/PCRE)TraitsNamespacesParsing HTMLComposer Dependency ManagerMagic MethodsAlternative Syntax for Control StructuresFile handlingMagic ConstantsType hintingMulti Threading ExtensionFilters & Filter FunctionsGeneratorsOperatorsConstantsUTF-8URLsObject SerializationPHPDocContributing to the PHP ManualString ParsingLoopsControl StructuresSerializationClosureReading Request DataType juggling and Non-Strict Comparison IssuesSecurityPHP MySQLiCommand Line Interface (CLI)LocalizationDebuggingSuperglobal Variables PHPUnit TestingVariable ScopeReferencesCompilation of Errors and WarningsInstalling a PHP environment on WindowsDatetime ClassHeaders ManipulationPerformanceCommon ErrorsInstalling on Linux/Unix EnvironmentsContributing to the PHP CoreCoding ConventionsUsing MongoDBAsynchronous programmingUsing SQLSRVUnicode Support in PHPFunctionsCreate PDF files in PHPHow to Detect Client IP AddressYAML in PHPImage Processing with GDMultiprocessingSOAP ServerMachine learningCacheStreamsArray iterationCryptographyPDOSQLite3SocketsOutputting the Value of a VariableString formattingCompile PHP Extensionsmongo-phpManipulating an ArrayExecuting Upon an ArrayProcessing Multiple Arrays TogetherSPL data structuresCommentsIMAPUsing Redis with PHPImagickSimpleXMLHTTP AuthenticationRecipesBC Math (Binary Calculator)Docker deploymentWebSocketsAPCuDesign PatternsSecure Remeber Mephp mysqli affected rows returns 0 when it should return a positive integerPHP Built in serverHow to break down an URLPSR

PHP Built in server

Other topics

Remarks:

An example of router script is:

<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
    return false;    // serve the requested resource as-is.
}  //the rest of you code goes here.

Running the built in server

php -S localhost:80

PHP 7.1.7 Development Server started at Fri Jul 14 15:11:05 2017
Listening on http://localhost:80
Document root is C:\projetos\repgeral
Press Ctrl-C to quit.

This is the simplest way to start a PHP server that responds to request made to localhost at the port 80.

The -S tells that we are starting a webserver.

The localhost:80 indicates the host that we are answering and the port. You can use other combinations like:

  • mymachine:80 - will listen on the address mymachine and port 80;
  • 127.0.0.1:8080 - will listen on the address 127.0.0.1 and port 8080;

built in server with specific directory and router script

php -S localhost:80 -t project/public router.php

PHP 7.1.7 Development Server started at Fri Jul 14 15:22:25 2017
Listening on http://localhost:80
Document root is /home/project/public
Press Ctrl-C to quit.

Parameters:

ColumnColumn
-STell the php that we want a webserver
<hostname>:<port>The host name and the por to be used
-tPublic directory
<filename>The routing script

Contributors

Topic Id: 10782

Example Ids: 32317,32318

This site is not affiliated with any of the contributors.