Skip to content

Conversation

aditya-zanjad
Copy link

@aditya-zanjad aditya-zanjad commented Apr 27, 2022

Added an alternate way to serve the app using the terminal command php codeholic serve

From the root directory, where README.md file is located, you can now run the following terminal command to serve the app.

php codeholic serve

FIRST NOTE
The file codeholic.php has been renamed to just codeholic.
This way we can just run php codeholic serve instead of php codeholic.php serve.


SECOND NOTE
In the fourth commit, added the ability to specify port number & host url for the command php codeholic serve.
Now, we can specify parameters '--port' & '--host'. If the user does not provide any value for --port argument, then its default value will always be 8080.

Some examples below:

php codeholic serve --host=localhost --port=8081
php codeholic serve --host=127.0.0.1
php codeholic serve --port=5000

THIRD NOTE
In the seventh commit, added the option to specify the parameter --max-port to decide the limit upto which to try to run the PHP's built-in server on before showing a failure message. The value of the parameter --max-port should always be equal to or greater than the value of the parameter --port.

If the user does not provide any value for --port argument, then its default value will always be 8080.

Also, there is a hard limit set on the value of --max-port. This means, the value of --max-port should never be greater than the addition of value of --port plus 100. This is done to make sure that the for loop in the program will not like run forever.

Some valid examples below:

php codeholic serve --max-port=8180
php codeholic serve --port=9000 --max-port=9100

Some invalid examples below:

php codeholic serve --max-port=9000
php codeholic serve --port=9000 --max-port=10000

@aditya-zanjad aditya-zanjad changed the title Serve app using 'php codeholic serve' command... An alternative way to run the app... Added a feature to serve app using 'php codeholic serve' command... An alternative way to run the app... Apr 27, 2022
@aditya-zanjad aditya-zanjad changed the title Added a feature to serve app using 'php codeholic serve' command... An alternative way to run the app... Added a feature to serve the app using the terminal command 'php codeholic serve' Apr 28, 2022
@thecodeholic
Copy link
Owner

That is awesome @aditya-zanjad. Thank you for it.
I will test it and as far as there are no issue I will merge this.

Copy link
Owner

@thecodeholic thecodeholic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is great. Thanks for contributing.

@@ -0,0 +1,2 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should completely ignore .vscode folder.

codeholic Outdated
}

// If default port is free, run PHP's built-in server on it
if (exec(`php -S $host:$port -t $pathToMainIndex`)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the default port is occupied and this code is executed. Code throws an error and does not try to allocate next port.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thecodeholic Thanks for notifying me about these issues. I'll try to fix them ASAP.

@aditya-zanjad
Copy link
Author

@thecodeholic Thank you for the feedback. The suggested changes are now implemented. Thank you.

@thecodeholic
Copy link
Owner

@aditya-zanjad Thank you for this.
I will review it and test and then merge if everything looks good.
I love the feature. Well Done.

@aditya-zanjad aditya-zanjad closed this by deleting the head repository Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants