How to run php script on linux server every second?

  cron, linux, php

Im new to this so im a little confused.
I have a PHP script that is in an infinite loop. It will never stop looping after i execute it once.
And i need to run it on my linux server.
I was thinking about using crontab,but apparently,it only can execute a script every minute. What i dont get is; If my PHP script is running in an infinite loop,do i need to only run it once and it would work fine,right?
So do i just need to use crontab to run my script ONCE,and then to run on restart,and it would work?

I wont post my script here because there is no need to. Just imagine something like

    <?php
for ($i = 1; $i <= 100;)
{
echo("anything");
}

And i need to run it forever on my server,and to run it if the server restarts.
If my logic is correct,could someone please show me some code on how would i do it?

EDIT: I also heard that PHP is not good for this (But i can’t change it,it needs to be PHP) and this infinite loop would take lots of Gigabytes of memory after a few days,and to solve that,i would need to tell crontab to reset my script every once in a while. Is that correct?

Source: Ask PHP

LEAVE A COMMENT