Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a php program continuously in the server?

Tags:

php

cron

daemon

i want to run a php program constantly in the server which would download some things and store them..

I was thinking of creating a script and running that in cron..

But i wonder is there any other simple method or light weight component which takes less memory in the server while running continuously ??

I thought of another simple thing,

creating a php script with infinite max_execution time and running the code inside a while(true) loop (indefinite loop) with some sleep and then starting the program using php..

Which would be the better available method to do this?

like image 202
Vijay Avatar asked Aug 22 '26 12:08

Vijay


1 Answers

I've created a library called LooPHP which helps abstract out all the while(1) craziness and provides the ability to add event sources (more or less it's a basic runloop you'd fine in GLib, Cocoa, node.js). There's a few of examples which can let you know if you like the style of writing (event based vs loop driven).

I'd suggest reading some of the other questions with PHP and daemon tags. Here is a few of my answers.

But honestly CRON is fairly lightweight and unless it needs to be real-time (or whatever that means to you) writing PHP into a daemon is more work than it's work.

like image 153
Kendall Hopkins Avatar answered Aug 24 '26 03:08

Kendall Hopkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!