Chron's avatar
Level 6

Address already in use

This error didn't occurred until now. Whenever I run php artisan serve, It gives me 127.0.0.1:8000, it works a couple of minutes but after that the page just keeps loading until I restart the server and gives me an error Failed to listen on 127.0.0.1:8000 (reason: Address already in use) and gives me other port. Is there a way to trace what uses the default port?

0 likes
18 replies
siangboon's avatar

you could use the netstat command to grep whether the port is in used and used by what service/process. Usually 8000 and above is not for system use hence most likely you have custom services listening on the port and not close it properly.

Anyhow, you may just ignore it and use other port number above 8000 instead

php artisan serve --port=8080
Chron's avatar
Level 6

@SIANGBOON - I tried changing the port and the issue is still the same.

1 like
Snapey's avatar

its probably conflicting with itself.

Remember that the php built in server can only run one request at a time and cannot listen for a new request until it has finished the last one. If you have any scheduler tasks, or are calling third party api then new web requests will be blocked until this has finished.

Better to use a proper web server

Lama Youz's avatar

@Snapey Hi

I've this problem in my sever .. when I call another requests while there is a request running then the new requests is blocked!

is there anyway to make the new requests to wait and not getting blocked??

Snapey's avatar

@Lama Youz they are waiting

best option is to use another type of web server

Lama Youz's avatar

@Snapey

They aren't waiting .. all requests will fail with the error "Address already in use"

What do you mean by another type of web server?

Snapey's avatar

@Lama Youz suggest you start your own question as this one is not related to your problem

1 like
diegoaurino's avatar

@chron !

Try the following on your project root folder:

php -S localhost:8000 -t public/

Check: https://www.php.net/manual/en/features.commandline.webserver.php

If the command above works, chances are that the problem is in your artisan installation.

Also, check if ps aux | grep -i portand ps aux | grep -i artisan return something strange.

If the problem persists, I would suggest you delete and reinstall your vendors folder.

Let me know if it helps.

1 like
Chron's avatar
Level 6

@DIEGOAURINO - I got this. ps aux | grep -i port

chronic+ 15764  0.0  0.1   6276  2096 pts/4    S+   18:20   0:00 grep --colour=auto -i port

ps aux | grep -i artisan

chronic+ 15750  7.0  2.0  97132 30300 pts/0    S+   18:19   0:00 php artisan serve
chronic+ 15757  0.0  0.1   6276  2188 pts/4    S+   18:19   0:00 grep --colour=auto -i artisan
diegoaurino's avatar

ps aux | grep -i artisan shows that you have other artisan serve running. Kill the process 15750 to see if it is the origin of your problems. Have you tried to run the PHP built-in server?

Chron's avatar
Level 6

@DIEGOAURINO - Yes. I tried it. Same problem. I terminated the artisan serve and the tab that runs php artisan serve said its terminated.

diegoaurino's avatar

@CHRON - I believe now that the problem is in your environment. Also, check your firewall system to list all opened ports.

Are your iptables configured properly? Check ArchLinux docs: https://wiki.archlinux.org/index.php/Category:Firewalls

As @siangboon suggested, you can use netstat for that. Use the following to list all network ports:

netstat -lntu

@snapey suggested you use a web server. I would do the same. You can install a LAMP server on Manjaro with ease.

https://wiki.archlinux.org/index.php/Category:Web_applications

But none of these will work if your Firewall or MAC are not properly configured.

https://wiki.archlinux.org/index.php/Security#Mandatory_access_control

Chron's avatar
Level 6

Okay, apparently dompdf is the culprit. I noticed that when I visit a page that goes to print view, the error occurred but it stopped after I modified my code. Thanks for helping everyone!

Snapey's avatar

dompdf perhaps requires a second thread and blocks for the reason I mentioned earlier

Please or to participate in this conversation.