Is it wise to use PHP for a daemon?

前端 未结 17 1453
庸人自扰
庸人自扰 2020-11-28 09:18

I wish to create a background process and I have been told these are usually written in C or something of that sort. I have recently found out PHP can be used to create a da

17条回答
  •  盖世英雄少女心
    2020-11-28 10:06

    Go for it. I had to do it once also. Like others said, it's not ideal but it'll get-er-done. Using Windows, right? Good.

    If you only need it to run occasionally (Once per hour, etc). Make a new shortcut to your firefox, place it somewhere relevant. Open up the properties for the shortcut, change "Target" to:

    "C:\Program Files\Mozilla Firefox\firefox.exe" http://localhost/path/to/script.php
    

    Go to Control Panel>Scheduled Tasks Point your new scheduled task at the shortcut.

    If you need it to run constantly or pseudo-constantly, you'll need to spice the script up a bit.

    Start your script with

    set_time_limit(0);
    ob_implicit_flush(true);
    

    If the script uses a loop (like while) you have to clear the buffer:

    $i=0;
    while($i

提交回复
热议问题