mohammed.yahya Posted June 17, 2008 Share Posted June 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/ Share on other sites More sharing options...
Xurion Posted June 17, 2008 Share Posted June 17, 2008 Yes you will be left hanging around waiting for the script to finish looping. You may want to look into things like phpmailer: http://phpmailer.codeworxtech.com/ Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-567361 Share on other sites More sharing options...
mohammed.yahya Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks for your reply...But, I don't want to use ready made solution. I want to do it myself......Can any body help me? Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-567924 Share on other sites More sharing options...
Stephen Posted June 18, 2008 Share Posted June 18, 2008 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>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-567931 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-567932 Share on other sites More sharing options...
mohammed.yahya Posted June 18, 2008 Author Share Posted June 18, 2008 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............. Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-568084 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-568161 Share on other sites More sharing options...
mohammed.yahya Posted June 18, 2008 Author Share Posted June 18, 2008 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...... :) Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-568228 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-568241 Share on other sites More sharing options...
mohammed.yahya Posted June 19, 2008 Author Share Posted June 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-568916 Share on other sites More sharing options...
mohammed.yahya Posted June 21, 2008 Author Share Posted June 21, 2008 No solution... my php is installed as an Apache module not as a CGI service....So I can not run it as a bash script. Is that right?? thanks Quote Link to comment https://forums.phpfreaks.com/topic/110590-php-and-multi-threading/#findComment-570812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.