0

I conduct online auctions on lamp stack, ubuntu, aws. I have a cron (postsale_cron.php) that runs every 15 minutes to process the auctions that ran in the previous 15 minute window. It looks in our queue database and pulls all auctions that were finished in that window and calls popen to run process_auction.php for each such auction. The expectation is that the cron will spawn this function for each auction so it processes multiple auctions in parallel.

When we run process_auction.php manually from command line for a single auction, it runs properly regardless of whether there are PHP notices or warnings.

When we run as cron through cron job, postsale_cron.php returns a message saying that it ran process_auction.php for all auctions (3 during test), but some or none actually run. Very inconsistent. It appears that if there is only one cron, it works. But if multiple, then it doesn't. It also appears that if there are any PHP Warnings or Notices, that process_auction.php instance does not finish and nothing thereafter runs/finishes. But very hard to tell. I have put write to file statements in process_auction.php so it can create separate logs for each process but they do not get created if there is a problem with any of the processes.


In postsale_cron.php:

$handle = popen("php $path $ClientID $end_date &","r"); // $path defined as /var/.../process_auction.php

$pstatus = pclose($handle); // close the stream created by popen();

$pstatus results are 0 for each auction


Process auction should run each auction independently, if some are exiting due to warnings, then remaining should complete without if they don't have errors but background processes seem to all halt

ggorlen
  • 44,755
  • 7
  • 76
  • 106
firpo
  • 43
  • 8
  • any insight would be appreciated – firpo Aug 17 '19 at 03:42
  • I'd love to hear insight on this as well. I'd never even heard of `popen` until you mentioned it! Fascinating. I guarantee that `popen` is the problem, however. Try running the cron job serially (i.e., process one auction at a time), and see A) if it all works correctly, B) if you can live with the speed. Since you're running this only every 15 minutes, unless you're eBay, you'll be long done before the next 15-minute cycle starts. Just my 2 cents. – FoulFoot Aug 17 '19 at 03:56
  • Resolved the problem thanks to @Cristian and this post: https://stackoverflow.com/questions/3819398/php-exec-command-or-similar-to-not-wait-for-result – firpo Aug 18 '19 at 17:55
  • Seems that php background child processes should not output to stdout or terminal. Doing so seems to hang everything up. When I revised the code to use the exec and start the processes using exec as command line entries, all worked perfectly – firpo Aug 18 '19 at 17:56

0 Answers0