0

openSuSE 13.2 when it's finished starting up I want to automatically run a php script and keep it running in the background. The script is a loop that never ends.. so once launched it shouldn't stop.

It doesn't need to write out any information to screen it will take care of that and generate it's own log file and emails as needed.

In the past I've used the following with bash scripts, but it doesn't work for php. I don't see this as a duplicate question as they relate to bash scripts etc NOT PHP.

- cp <yourscriptname> /etc/init.d/
- insserv <yourscriptname>

chkconfig --list | grep <yourscriptname>

Can anyone advise the best way to do this.

Thanks

3
  • Possible duplicate of Run automatically program on startup under linux ubuntu Commented Jul 5, 2016 at 12:41
  • I would use something like supervisord to start / restart / monitor the process. Commented Jul 5, 2016 at 12:42
  • @AndréRoggeriCampos - This isn't a duplicate as the other questions relate to bash scripts etc, NOT PHP Commented Jul 5, 2016 at 12:45

1 Answer 1

1

You can make your php script executable. The way is to add #!/usr/bin/php (or whatever your php path is) to the top of the script, and then chmod +x <script>

Then your original solution should work

Sign up to request clarification or add additional context in comments.

4 Comments

When I try this and start it it fails.. Failed to start test.php.service: Unit test.php.service failed to load: No such file or directory. What am I doing wrong.
And does it all execute and run correctly even if PATH is unset?
Does the filename have a space? Maybe remove it. The non-found file seems to be Unit test.php.service, and I'm not sure what is looking for that, or why it doesn't have a path associated.
I've got this working. created a file called test in /etc/init.d containing #!/bin/sh /usr/bin/php /home/rocket/Downloads/test.php &, chmod +x it and then insserv test now seems to be working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.