Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:20:24+00:00 2026-06-07T22:20:24+00:00

PHP 5.4 comes with a built-in server for development purposes. This is the kind

  • 0

PHP 5.4 comes with a built-in server for development purposes. This is the kind of thing I’ve been waiting for months, because up until now I’ve had to sort of hack together a PHP script that listens for incoming connections and handles them (because I don’t want to go to the trouble and overhead of installing an actual server).

The main thing left for me to worry about is: how can I have a port assigned?

In my PHP script, I used to do this:

socket_bind($sock,"localhost",0) or die("Could not bind socket");
socket_getsockname($sock,$ip,$port);

$port would then be the port number assigned by the OS based on what is available.

I was just wondering if any such feature existed in PHP’s built-in server and, if so, what the command line should be to access it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:20:26+00:00Added an answer on June 7, 2026 at 10:20 pm

    Answering my own question (again), I used the following batch script to find an available port and start the server:

    @echo off
    for /L %%a in (8000,1,8100) do netstat /a /n | find "%%a" | find "LISTENING" >NUL || set tmp_phpserver=%%a&& goto found
    echo No free ports found in range 8000-8100...
    pause
    exit
    :found
    echo Starting server on port %tmp_phpserver%
    start "PHP server %~p1 on localhost:%tmp_phpserver%" /min php -S localhost:%tmp_phpserver%
    echo Server started
    timeout 3
    start http://localhost:%tmp_phpserver%/%~nx1
    set tmp_phpserver=
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using PHP API posts ' likes comes in this detailed format [likes] =>
Yes, there's a built-in web server in the upcoming release of PHP 5.4 which
I'm clueless when it comes to PHP and have a script that emails the
I am looking for the simplest php framework that comes integrated with dojo. I
I'm a novice when it comes to SQL and PHP, and I'm trying to
I am using PHP, i want to display a string which comes as title
How to create simple PHP COMET server page displaying current time? I need code
I created an Archive list ( also this is my archive.php codes ) on
I've built a ZF app using 1.10 for deployment on RHEL server in a
So, I have built on this system for quite some time, and it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.