Skip to content

Instantly share code, notes, and snippets.

@shuantsu
Created May 15, 2026 17:52
Show Gist options
  • Select an option

  • Save shuantsu/743e4289b75b24039fd7d06c4a963f35 to your computer and use it in GitHub Desktop.

Select an option

Save shuantsu/743e4289b75b24039fd7d06c4a963f35 to your computer and use it in GitHub Desktop.
0.0.0.0 wifi php server shell script qr code support vscode tasks support
#!/bin/bash
PORTA=8001
IP=$(ip -4 addr show enp34s0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
COMANDO="php -S 0.0.0.0:$PORTA -t ./poc"
status_servidor() {
lsof -Pi :$PORTA -sTCP:LISTEN -t >/dev/null
}
ligar() {
if status_servidor; then
echo "Aviso: O servidor já está rodando em http://$IP:$PORTA"
else
setsid $COMANDO > /dev/null 2>&1 &
sleep 0.5
echo "Servidor iniciado em: http://$IP:$PORTA"
echo ""
# Gera o QR Code direto no terminal
curl -s "https://qrenco.de/http://$IP:$PORTA"
echo ""
fi
}
desligar() {
# Procura o ID do processo (PID) direto na porta 8001, independente do shell
PID=$(lsof -t -i:$PORTA -sTCP:LISTEN)
if [ ! -z "$PID" ]; then
kill -9 $PID
echo "Servidor desligado com sucesso."
else
echo "Aviso: Nenhum servidor rodando na porta $PORTA."
fi
}
case "$1" in
up)
ligar
;;
down)
desligar
;;
restart)
echo "Reiniciando o servidor..."
desligar
sleep 1
ligar
;;
*)
echo "Uso correto: $0 {up|down|restart}"
exit 1
;;
esac
{
"version": "2.0.0",
"tasks": [
{
"label": "Server Up",
"type": "shell",
"command": "./server.sh up",
"runOptions": { "instanceLimit": 1 },
"presentation": {
"group": "server-process",
"panel": "shared",
"clear": true,
"reveal": "always",
"showReuseMessage": false
}
},
{
"label": "Server Down",
"type": "shell",
"command": "./server.sh down",
"runOptions": { "instanceLimit": 1 },
"presentation": {
"group": "server-process",
"panel": "shared",
"clear": true,
"reveal": "always",
"showReuseMessage": false
}
},
{
"label": "Server Restart",
"type": "shell",
"command": "./server.sh restart",
"runOptions": { "instanceLimit": 1 },
"presentation": {
"group": "server-process",
"panel": "shared",
"clear": true,
"reveal": "always",
"showReuseMessage": false
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment