Jump to content

php-cli in background


RobertP

Recommended Posts

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).

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.

  • 2 weeks later...

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 &');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.