1

I have a PHP script that launches another script in the background. Recently my host upgraded PHP and this pair relaunches the background script multiple times a second where it should only be launching once.

I reduced the two scripts to their most basic form and they still have the problem.

start.php:

<?php exec("/home/s*****/public_html/sandbox/process/pushupdate.php &"); ?>

and pushupdate.php:

#!/usr/bin/php -q
<?php mail('*********@gmail.com', 'test output', 'testing'); ?>

The email never gets sent, but that may be a problem with my hosting company.

2
  • For the record, removing #!/usr/bin/php -q and running exec("/usr/bin/php /home/s*****/public_html/sandbox/process/pushupdate.php &"); has the same results. Running from a cron job however, works. Commented Aug 26, 2010 at 19:02
  • I have tried this test on several different servers, and the only common factor I can find is Cpanel. Commented Apr 29, 2011 at 21:08

1 Answer 1

2

Do your host allow cronjobs? If yes, use them instead of calling pushupdate.php from another PHP script. You'll solve two problems: if no-one is visting your site, your mail queue will still be processed. If your site is busy, there won't be unnescessary calls to pushupdate.php

A possible cause is a redirect, e.g. example.com to www.example.com.

start.php is called by the visitor, right?

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

6 Comments

start.php is NOT called by the visitor. It is called by an admin from behind a password protected directory. You can't see it here, but there was logic to not launch if it was already running.
@David Beck: you could also use cron jobs to call scripts in admin area, by calling the php command: "php /home/s*****/public_html/sandbox/process/pushupdate.php >/dev/null 2>&1" Actually I thought you should call the php cammand also in your exec.
Running as a cron works. I would like to find out why running using exec doesn't work though.
If you look in your Apache access logs, does 'start.php' occurs more than once in a short term?
The logs do not show more than one request (as it should). I was able to run the script on my local computer without any problem.
|

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.