0

I have a mailing function and 100k email ids. I want to call a function multiple times like 10 times and in each time it will process 10k emails. I want to call this function without waiting for response just call a function and another and another without getting response.

I tried pthread for multi threading but can't run it successfully.

I am using my sql database

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

You can use multiple PHP processes for that, just like you can use multiple threads, there isn't much of a difference for PHP, as PHP is shared nothing.

You probably want to wait for it to finish and to notice any errors, but don't want to wait for completion before launching another process. Amp is perfectly suited for such use cases. Its amphp/parallel package makes multi-processing easier than using PHP's native API.

You can find a usage example in the repository.

kelunik
  • 6,750
  • 2
  • 41
  • 70
  • Seems like it is only compatible with PHP 7.0 or higher? Any possibilities I can use for lower PHP version maybe V 5.0x ? – Shyam Bhimani Nov 29 '17 at 19:58
  • @ShyamBhimani PHP 5.0, seriously? That has been released in 2004. PHP 5.x is out of active support and won't receive any bug fixes anymore. Consider upgrading. – kelunik Nov 29 '17 at 20:39
0

php name_of_script.php &>/dev/null &

this line will start your script in the background. I suppose you do not want to control a critical process like sending mails from your browser? What if your connection breaks a few seconds?

If so: still use command line approach, but using exec

$command = '/usr/bin/php path/to/script.php & echo $!');

Ivo P
  • 1,722
  • 1
  • 7
  • 18