1

Let me try to explain to you what i need:

the user creates a post on the site and choose which users can have access to this post. When the user submits the information, each person chosen to have access to post receives an email warning. To perform this I use ajax through jquery. The problem is that this process may be too long until all the emails have been sent.

So I thought the process would work as follows:

1rst - Save the post;

2snd - Save the information of emails (subject, recipient, etc.) in a database table;

3th - run a php file in "parallel" to fetch the information of emails and send them - with the goal of not having to wait for it to execute.

Is the third step possible?

I hope i explain me well :)

Thank you all.

Pedro
  • 77
  • 8
  • I already have answer to this question: http://stackoverflow.com/questions/25700904/how-to-run-php-code-in-the-background-on-unix-server – sugunan Sep 26 '14 at 11:08
  • possible duplicate of [php exec command (or similar) to not wait for result](http://stackoverflow.com/questions/3819398/php-exec-command-or-similar-to-not-wait-for-result) – Thomas Jensen Sep 26 '14 at 11:13
  • Thank you. But there's something not working. I made this `echo "Script start at: " . date('h:i:s') . "
    "; exec('bash -c "exec nohup php exect.php > /dev/null 2>&1 &"'); echo "Script end at: " . date('h:i:s');` and in exect.php this ` $handling = fopen(dirname(__FILE__) .'/error_log', 'a+'); fputs($handling, 'Start Execute!!! - server time: ' .$act_date_time_server .' - PT time: ' .$act_date_time ."\r\n"); sleep(1000); fputs($handling, 'End Execute!!! - server time: ' .$act_date_time_server .' - PT time: ' .$act_date_time ."\r\n"); fclose($handling); `
    – Pedro Sep 26 '14 at 11:36

1 Answers1

1

If you have access to the server crontab, simply setup a new crontab to run every minute and execute the mail sending. This way it's not related to your workflow, so you can store the emails somehow in files or database, etc.etc., and send out later from a different script.

crontab -e -u (webserver user)
Gipsz Jakab
  • 433
  • 3
  • 9
  • Thank you for answer. I have a lot of cronjobs, but for this the best should be use something like exec(). Thank you. – Pedro Sep 26 '14 at 11:51
  • I would still suggest cron job: - you can avoid parallel running of mail senders (can cause your system to hang completely!) - it's really independent, and in case of hack attempt, they're unable to run "just anything" what they want through your script ... (So it is more secure this way) – Gipsz Jakab Sep 27 '14 at 11:43