0

In my php project i should have some background process , but in safe mode , because I'm running it on a shared host.

For example my background process code is in the file bg.php and I want it to be executed , write at finish of another specific script.( or maybe with some delay )
I searched a lot. some suggested libraries like beanstalkd but i think this library is heavy for my simple background process and also doesn't have good doc for PHP. some others said functions like exec() which is not possible in safe mode.

  • 1- Does anyone have a simple solution for this problem?
  • 2- I were also mentioned by cron jobs existing in cpanel which prepare tasks to be executed on a specific time. can I use this option to solve my problem in some way?

I noted I want a simple and lightweight solution. any suggestions appreciated deeply.

Jordan Richards
  • 532
  • 3
  • 18
Aliweb
  • 1,891
  • 3
  • 21
  • 44

1 Answers1

1

It's not possible use a PHP file served by a HTTP Server because all proceses will die after the request end.

So cPanel cron is a good option, you don't need to have the cron entry always enable, just setup once the entry and disable it after the script start to run.

Only you'll need add & at the end of your cron command to make it run as background.

Maks3w
  • 6,014
  • 6
  • 37
  • 42
  • would you please explain more? I only worked with corn jobs in visual form and set to run jobs for example in 5 minutes **from now**. but I don't know how to tell it for example run in 5 minutes **at finish of a script**. – Aliweb Sep 16 '12 at 17:50
  • IIRC in cPanel you can mark a cron job as enable or not, if not simply add or remove the entry. I say this because you won't spawn a new background process each X minutes. You can improve your script to detect other scripts in execution, for example making an empty file as flag. Of course I'm talking about one script wich each permantly in background. If you script is for pull some info each X seconds then you can configure the Cron as always you did – Maks3w Sep 16 '12 at 17:56