How to run a php file forever in ubuntu by command line

advertisements

I am using web-socket in php to run a chat service problem is when i close the command line the connection also close , is there a solution so that the chat service can run forever . i am using this command

php -q server.php


create a php file on your server name it as start_server.php and post this content

            <?php

            $shell_command = "php -q server.php > /dev/null &";
            shell_exec($shell_command);

            ?>

now execute this command

php start_server.php