Jump to content

Recommended Posts

Hi all,

 

I am developing a mailing list in my website using PHP. I will make a loop to send an email to maybe 1000 emails that is stored in the database.

 

My question is that:

 

When I press submit in my form in order to send a text as an email. If I have 10000 emails in my database. Then, the code will loop for 10000 times. In this case, is the page going to hang untill all the loops finishes or I can surf the website while the loop is running?

 

If it will hang.....How can I resolve this issue? Is there a multi-threading in PHP?

 

What is the solution???

 

Please, help.

Link to comment
https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/
Share on other sites

You could do something like: (by the way, the mysql_query should be the select one getting the emails from the db)

<?php
$_l=$_GET["l"];
if (!$_l) {
  $_l=0;
}

$_nl=$_l+1000;

//Insert loop here
//Put below where you put your query, just add the end of it to it (from the LIMIT on)
mysql_query("[YOUR QUERY] LIMIT ".$_l.",1000");
//End loop

echo("<html>
<head>
<META http-equiv='refresh' content='5;URL=page.php?l=".$_nl."'>
</head>
</html>");
?>

Make the email script a second file, and call it with shell_exec() and send it into the background :)

 

<?php
shell_exec("/dir/blah/script_to_exec.sh > /dev/null 2>&1 &");
?>

 

Make the shell script include the calls to php. This is a way I used for a program to work in the background - not php.

 

Alternatively, you can execute php scripts directly, instead of having to make a shell script. The choice is yours.

 

Hope this helps

Stephen, Jabop

 

Thank you very much for your solutions. I will try them and tell you the results...

 

But, I need you to explain to me your codes please:

 

Stephen:

Whay do u mean by this?

<?php

$_l=$_GET["l"];

if (!$_l) {

  $_l=0;

}

 

$_nl=$_l+1000;

 

 

Jabop:

Can u tell me more how to send an email using a shell program (which language to use)?

And, my website is in a shared web hosting server. Can I put the shell script in this envirunment and how?

 

 

thank you very much............. :)

 

mohammed.yahya: You can call php scripts through shell_exec(). I used a shell script (bash) to run a program to convert a file. This was the best solution for my problem. You would probably do well if you just had a php file, and ran it with shell_exec(), passing your variables to the *external* php script.

Jabop: Acually I am a java programmer and I am beginner in PHP. lets say that I have a PHP file that should take 3 parameters. How can I pass them to the bash script in PHP.

 

Suppose my PHP file is : send.php

And the parameters are: textToBeSent (string); langFlag (boolean)

 

thanks a lot......  :) :)

Ah, good call. If it were a shell script:

 

#!/bin/bash

/usr/local/bin/ffmpeg -i $1 -ar $2 -acodec libmp3lame -ab $3 -vcodec flv -b 300k -s $4x$5 -g 150 -cmp 2 -subcmp 2 -mbd 2 -y -flags +aic+cbp+mv0+mv4+trell $6 $7;

/usr/local/bin/flvtool2 -U $6 $7

 

Those variables are passed by this (PHP):

 

<?php
$ProcessMethod="> /dev/null 2>&1 &";
shell_exec("/var/www/html/yourdirectory/convert.sh ".escapeshellarg($TempFile)." ".escapeshellarg($srcAR)." ".escapeshellarg($srcAB)." ".escapeshellarg($srcWidth)." ".escapeshellarg($srcHeight)." ".escapeshellarg($FinalFile)." ".$ProcessMethod);
sleep(4);
chmod($FinalFile,0664);
?>

 

I believe you can make sense of that. If you want to go this route, you can just change the variables, and pass them like you see above.

 

Ah, good call. If it were a shell script:

 

Could it be another php script?? So when I click submit the action goes to a page that call that php script through shell_exec()

 

Another question.... How can I run a php script through a bash script?

 

I got confused as I do not hava a linux background...

 

What is the best solution for my problem?

 

many thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.