RobertP Posted September 29, 2011 Share Posted September 29, 2011 hello everyone, i plan to host my software on a dedicated server, now is it possible to run php-cli ( used for cron ) in the background ... and if so how is it possible? also, is it possible to make php sleep? maybe something with while(time()<_interval){} ?? Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/ Share on other sites More sharing options...
trq Posted September 29, 2011 Share Posted September 29, 2011 Cron jobs already run in the background. sleep. Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/#findComment-1273802 Share on other sites More sharing options...
dalecosp Posted October 1, 2011 Share Posted October 1, 2011 It really varies by hosting company. I used to work for a company that hosted sites for other companies on FreeBSD. PHP cli on FreeBSD was "php -r", which is a single-line CLI tool used via SSH. When run via cron, scripts used /usr/local/bin/php -q, generally. I program for a company now that uses a California hosting company running either RedHat or CentOS. There I have access to "php -a" for interactive work via SSH, and cron runs scripts from /usr/bin/php, with or without "-q" (doesn't seem to matter for some reason). Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/#findComment-1274786 Share on other sites More sharing options...
dalecosp Posted October 1, 2011 Share Posted October 1, 2011 is it possible to make php sleep? maybe something with while(time()<_interval){} ?? Ooh, don't do that ... especially on a shared server ... no need to waste those CPU cycles ;-) sleep(), or usleep() (for microseconds), as our esteemed moderator has already mentioned. Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/#findComment-1274788 Share on other sites More sharing options...
RobertP Posted October 2, 2011 Author Share Posted October 2, 2011 thank you so much for your responses, sleep seems to do the trick Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/#findComment-1274878 Share on other sites More sharing options...
polycap9 Posted October 13, 2011 Share Posted October 13, 2011 I salute you thorpe Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/#findComment-1278911 Share on other sites More sharing options...
gizmola Posted October 13, 2011 Share Posted October 13, 2011 I have developed lots of cli programs that run from cron. There is also at. However, when you use the word background, this has a special meaning. I have lots of tasks that are started by cron and then use exec. The secret is to use *nix shell's built in ability to background a process using &. exec('/usr/bin/php -f somescript.php &'); Quote Link to comment https://forums.phpfreaks.com/topic/248075-php-cli-in-background/#findComment-1279114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.