Skip to content
Advertisement

How to refresh changes in swoole PHP

I created one folder with two files, one is index.php and one is Dockerfile and in terminal I run php index.php and it started on http://127.0.0.1:9501/, but when I change hello world in something else, it doesn’t show new change on that link.. it stays hello world. I am trying to learn Swoole and I don’t know how to work with this.. Also I created in same folder Dockerfile

index.php

<?php

use SwooleHttpServer;
use SwooleHttpRequest;
use SwooleHttpResponse;

$server = new SwooleHTTPServer("127.0.0.1", 9501);

$server->on("Start", function(Server $server)
{
    echo "Swoole http server is started at http://127.0.0.1:9501n";
});

$server->on("Request", function(Request $request, Response $response)
{
    $response->header("Content-Type", "text/plain");
    $response->end("Hello Worldn");
});

$server->start();

Dockerfile

FROM php:8.1.0-cli

RUN apt-get update && apt-get install vim -y && 
    apt-get install openssl -y && 
    apt-get install libssl-dev -y && 
    apt-get install wget -y && 
    apt-get install git -y && 
    apt-get install procps -y && 
    apt-get install htop -y

RUN cd /tmp && git clone https://github.com/openswoole/swoole-src.git && 
    cd swoole-src && 
    git checkout v4.11.0 && 
    phpize  && 
    ./configure --enable-openssl --enable-swoole-curl --enable-http2 --enable-mysqlnd && 
    make && make install

RUN touch /usr/local/etc/php/conf.d/openswoole.ini && 
    echo 'extension=openswoole.so' > /usr/local/etc/php/conf.d/zzz_openswoole.ini

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init

RUN apt-get autoremove -y && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/usr/local/bin/dumb-init", "--", "php"]

And when I run,

docker build -f ./Dockerfile -t openswoole-php .

I am not able to build docker image for php-swoole I get error

executor failed running [/bin/sh -c cd /tmp && git clone https://github.com/openswoole/swoole-src.git &&     cd swoole-src &&     git checkout v4.11.0 &&     phpize  &&     ./configure --enable-openssl --enable-swoole-curl --enable-http2 --enable-mysqlnd &&     make && make install]: exit code: 2

Advertisement

Answer

I found solution to stop the web server, press Control+C. And again run php index.php

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement