Page 1 of 1
new error messages
Posted: Thu May 10, 2007 3:43 am
by roscoe
Fatal error:
Uncaught Error of type [swift_fileexception] with message [Disk Caching failed. Tried to write to file at [/tmp/b205275b9b0a931196eb797828de5529dbl_le] but failed. Check the permissions, or don't use disk caching.]
@0 swift::send() in /home/addictive/public_html/control/mail_pcp.php on line 147
@1 swift_message::build() in /home/addictive/public_html/control/mylib/Swift.php on line 474
@2 swift_message::builddata() in /home/addictive/public_html/control/mylib/Swift/Message/Mime.php on line 493
in /home/addictive/public_html/control/mylib/Swift/Errors.php on line 99
So I did the dump suggestion from the previous post. It did just 81 emails out.
here is an example of the dump
Checked the 147 on the script I wrote:
Code: Select all
$sent = $swift->send($message, $sendout, $sender);
surely this isn't because it isn't a batch?
[/quote]
Posted: Thu May 10, 2007 4:00 am
by roscoe
Further more, it has now done 147 so it seems to be doing the mailouts BUT
I received back one mail, it had the attachment no attached, but had tried to translate it into the email:
--_=_swift-9799613334642d565794cb9.44511748_=_
Content-Type: multipart/alternative;
boundary="_=_swift-11799258514642d5657a9f29.58817839_=_"
Content-Transfer-Encoding: 7bit
--_=_swift-11799258514642d5657a9f29.58817839_=_
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
record 3
If you wish to remove yourself from this mailing list at any time use the following link:
http://www.pc.com/unsubscribe.html
Thank you!
--_=_swift-11799258514642d5657a9f29.58817839_=_--
--_=_swift-9799613334642d565794cb9.44511748_=_
Content-Type: application/msword; name="Proposal toWATERSHED.doc"
Content-Transfer-Encoding: base64
Content-Description: Proposal toWATERSHED.doc
Content-Disposition: attachment; filename="Proposal toWATERSHED.doc"
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAAGAAAA1wIAAAAA
AAAAEAAA2QIAAAEAAAD+////AAAAANECAADSAgAA0wIAANQCAADVAgAA1gIAAP//////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
///////////////////////////////////spcEAMyAJBAAA+BK/AAAAAAAAEAAAAAAABAAA
X2MAAA4AYmpiakOHQ4cAAAAAAAAAAAAAAAAAAAAAAAAJBBYALWIBACHtAAAh7QAAHl8AAAAA
AABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAD//w8A
AAAAAAAAAAAAAAAAAAAAAGwAAAAAAMoFAAAAAAAAygUAAMoFAAAAAAAAygUAAAAAAADKBQAA
AAAAAMoFAAAAAAAAygUAABQAAAAAAAAAAAAAAN4FAAAAAAAA1EgAAAAAAADUSAAAAAAAANRI
AAA4AAAADEkAAHwAAACISQAARAMAAN4FAAAAAAAArmYAADoBAADYTAAASAEAACBOAAAWAAAA
Posted: Thu May 10, 2007 7:29 am
by Weirdan
You need to check the last line from the stacktrace, not the first. Perhaps there's not enough space on the drive where swift tried to cache the file data.
Posted: Thu May 10, 2007 7:56 am
by roscoe
You need to check the last line from the stacktrace, not the first. Perhaps there's not enough space on the drive where swift tried to cache the file data.
the last dump is as above, How would I find or do the stack trace and as to space it is commercial hosting and should run at least 200 emails at a time
Posted: Thu May 10, 2007 9:18 am
by Chris Corbyn
Please post your code again so I can see what's going on. That error comes back when fopen()/fwrite() fails and fwrite() only fails if the file cannot be written to.
Posted: Thu May 10, 2007 9:43 am
by roscoe
OK Here is the script:
Code: Select all
//Check if the required fields were sent
// Redirect back to the form if not
set_time_limit(0);
ignore_user_abort();
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table="alldone"; $z = 0;
$today =date("Ymd");
$sql = "SELECT * FROM $table WHERE mydate = '$today'";
$results = mysql_query($sql) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
$thecat = $row["catcompleted"];
$z = 1;
exit;
}
//Copy into global variables
$name = "PC";
$email = "info@pc.com";
//Validate the email address using a regex (I suggest you use a better one than this!!)
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if($z==0){
//ready to roll
$foundit=0;
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$yes="live";
$today =date("Ymd");
$counting = 0;
$sql = "SELECT * FROM $table WHERE status = '$yes' AND startdate<='$today' AND enddate != '$today'";
$results = mysql_query($sql) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
$myid = $row["id"];
$mycat = $row["cat"];
$foundit=1;
$counting = $counting +1;
// get the mail out
if ($mycat=="(xxx)"){
$mycat=1;
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$sql1 = "UPDATE $table set cat = '$mycat' where id = '$myid'";
$results1 = mysql_query($sql1) or die("An error ocurred :".mysql_error());
}
// echo "<br>CONTROL $myid, $mycat";
require_once "mylib/Swift.php";
require_once "mylib/Swift/Connection/Sendmail.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
//$swift =& new Swift(new Swift_Connection_SMTP("your_smtp_server.tld"));
//Try to connect using /usr/sbin/sendmail -bs
$sendmail =& new Swift_Connection_Sendmail();
$sendmail->setTimeout(10); //3 seconds
$swift =& new Swift($sendmail);
if ($foundit==1){
// pick up the id of content
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "content";
//$yes="live";
// $today =date("Ymd");
$sql2 = "SELECT * FROM $table WHERE id = '$myid'";
$results2 = mysql_query($sql2) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results2)) {
$title = $row["mysubject"];
$mycontent = $row["mycontent"];
$myattach = $row["myattach"];
$myfilename = $row["attfile"];
echo"<br>CONTENT $title, $mycontent, $myattach, $myfilename";
}
// I now have the content so lets get the addresses for the cat
if( $myattach=="y") {
//there is a file to attach $myfilename = $row["attfile"];
$file_path = " /home/addictive/public_html/mailattachers/";
// $file_name = $_FILES["attachment"]["name"];
$file_name = $myfilename;
$full_file_path = "/home/addictive/public_html/mailattachers/".$file_name;
// $file_type = $_FILES["attachment"]["type"];
$file_type = "application/msword";
// echo"<br> $full_file_path";
//Everything looks ok, we can start Swift
}
//Everything looks ok, we can start Swift
$closing ="\n\nIf you wish to remove yourself from this mailing list at any time use the following link:\nhttp://www.pcpluton.com/unsubscribe.html\n\nThank you!\n\n";
$mycontent = $mycontent.$closing;
// strip slashes
echo"<br>THE CONTENTS email $mycontent";
//Create a Swift instance new Swift_Connection_Sendmail()
$body = stripslashes ($mycontent);
$sender =& new Swift_Address($email, $name);
$countingmail=0;
$table = "mailouts";
//$yes="live";
// $today =date("Ymd");
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$sql3 = "SELECT * FROM $table WHERE cat = '$mycat'";
$results3 = mysql_query($sql3) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results3)) {
$sendout = $row["myaddress"];
$yourname = $row["myname"];
$countingmail=$countingmail+1;
//$sendout = $_POST["to"];
//Create the sender from the details we've been given
$mytime = date("g:i");
//Create the message to send
$message =& new Swift_Message($mytime." ".$title." ".$yourname);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($full_file_path), $file_name, $file_type));
}
//Try sending the email
// var_dump($sendout); var_dump($sender);
$sent = $swift->send($message, $sendout, $sender);
//Disconnect from SMTP, we're done
echo"<br>counting = $countingmail";
}
// echo"<br>counting = $countingmail";
// done the first mailout
//$swift->disconnect();
// sleep(1);
}
// end of if
// update file from here
$table = "categories";
$full = "FULL";
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$sqlA = "SELECT * FROM $table WHERE mycounter != '$full'";
$resultsA = mysql_query($sqlA) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($resultsA)) {
$finalcat = $row["cat"];
}
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$yes="dead";
$today =date("Ymd");
$sqlx = "UPDATE $table SET status = '$yes', enddate = '$today' WHERE cat = '$finalcat'";
$resultsx = mysql_query($sqlx) or die("An error ocurred :".mysql_error());
$newcat=$mycat+1;
//Update control set cat = '$newcat' where id = '$myid'
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$sqlx = "UPDATE $table set cat = '$newcat', enddate = '$today' where id = '$myid'";
$resultsx = mysql_query($sqlx) or die("An error ocurred :".mysql_error());
//require_once "mylib/Swift.php";
//require_once "mylib/Swift/Connection/Sendmail.php";
//if (is_writable("/tmp"))
//{
// Swift_CacheFactory::setClassName("Swift_Cache_Disk");
// Swift_Cache_Disk::setSavePath("/tmp");
//}
//$sendmail =& new Swift_Connection_Sendmail();
//$sendmail->setTimeout(10); //3 seconds
//$swift =& new Swift($sendmail);
} //end first while
} // if z=0
$swift->disconnect();
if ($sent)
{
header("Location: success.php");
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table="alldone"; $x = 1;
$today =date("Ymd");
$sqlC = "UPDATE alldone SET mydate='$today', catcompleted = '$mycat' WHERE b1='$x'";
$myresultZ = mysql_query($sqlC) or die("An error ocurred :".mysql_error());
mail("ros@successuk.com", "PHP Script is done for $cat", "Finished on " . date("m j, Y g:i a"));
exit();
}
else
{ echo"sending_failed";
exit;
header("Location: form.php?error=sending_failed");
exit();
}
It does the first one of 55 emails no probs but the second one gets to 49 and bombs. I tried closing the connection and reopening it (you can see the // out steps)
It seems to be the Swift_Cache_Disk is unable to write which equates to an email without an attachment, sometimes with the blurb above and sometimes just blank.
I really want to get this one working, surely sending the amount of emails (and the attachment is always less than 500kb)
Posted: Sun May 13, 2007 6:25 am
by Chris Corbyn
This is almost certainly a problem on your server. If the attachment is always less than 500KB, don't use the disk cache and you'll work around the issue.
Just comment out these lines:
Code: Select all
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
New Error message
Posted: Mon May 14, 2007 3:50 am
by roscoe
OK remmed out cache bits.
New error:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 514472 bytes) in /home/addictive/public_html/control/mylib/Swift/Events/CommandEvent.php on line 49
this line is
Code: Select all
function setString($string)
{
$this->string = (string) $string;
}
in CommandandEvent.php
Is this the server also??
Posted: Mon May 14, 2007 4:06 am
by Chris Corbyn
Your server is running out of memory. This is the risk when sending attachments without the disk cache. How big of an attachment are you sending? Up to about 2.5MB should be fine on a 8MB memory limit, but it varies from server to server.
I've been thinking about the disk cache. Is it possible your host are cleaning out /tmp? Try using a different temp folder somewhere within your home folder.
Posted: Mon May 14, 2007 5:07 am
by roscoe
it seems that with mailouts the host allows so much in size per hour. Although the attachments are not bigger than 500kb, when you add them all up the limit would be 50 x 1mb attachments per hour max. So I am going to have to build a timer in to allow 70 mins per spurt of emails and max 50 per time to ensure no failures.
The only way I can think of doing it (I am not sure how to reset the tmp folder to my space in swift) is to have a table with time recorded, test to see if time now is 70 mins after time set in db and then send a 50 then save time again and off we go again.
Posted: Mon May 14, 2007 6:57 am
by Chris Corbyn
Have you changed your code since the example above? I pasted it into my editor because I could not see where the curly braces pair up.
It appears you are creating loads of instances of Swift in the loop. In fact, the majority of the code you posted is in a loop.
Posted: Mon May 14, 2007 7:25 am
by roscoe
You are quite correct, the script does several loops inside a loop.
I am changing the script right now, but I will post the script and explain.....
Code: Select all
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table="alldone"; $z = 1;
$today =date("Ymd");
//reading the main table to see if we have done the latest mailout in the last 65 mins
$servertime = date("h:i:s");
$sql = "SELECT * FROM $table WHERE mydate <= '$today'";
$results = mysql_query($sql) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
$thecat = $row["catcompleted"];
$mytime = $row["b2"];
// echo "time is $mytime";
// split time up and add 1 hr 5 mins
$timepieces = explode(":", $mytime);
// echo "<br>$timepieces[0],$timepieces[1]";
$hour =$timepieces[0] +1;
$mins =$timepieces[1] +5;
// echo "<br>$hour,$mins";
$newtime = $hour.":".$mins.":00";
if ($servertime >$newtime){$z = 0;} else {$z=1;}
// echo $z;
if ($z=1)
{exit;}
}
//Copy into global variables
$name = "PC";
$email = "info@pc.com";
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if($z==0){
//ready to roll loop to send mail out
//decide the highest category
$table = "categories";
$full = "FULL";
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$sqlA = "SELECT * FROM $table WHERE mycounter != '$full'";
$resultsA = mysql_query($sqlA) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($resultsA)) {
$finalcat = $row["cat"]; }
if ($thecat == $finalcat) {$mycat=0;}
$mycat = $thecat +1;
$foundit=0;
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$yes="live";
$today =date("Ymd");
$sql = "SELECT * FROM $table WHERE status = '$yes' AND startdate<='$today' AND cat = '$mycat' limit 1";
$results = mysql_query($sql) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
$myid = $row["id"];
$foundit=1;
// get the mail out
//echo "<br>CONTROL $myid, $mycat";
// This is where I call Swift as long as I can find a mail out ready to go
require_once "mylib/Swift.php";
require_once "mylib/Swift/Connection/Sendmail.php";
//Enable disk caching if we can
//if (is_writable("/tmp"))
//{
// Swift_CacheFactory::setClassName("Swift_Cache_Disk");
// Swift_Cache_Disk::setSavePath("/tmp");
//}
//Create a Swift instance
//$swift =& new Swift(new Swift_Connection_SMTP("your_smtp_server.tld"));
//Try to connect using /usr/sbin/sendmail -bs
$sendmail =& new Swift_Connection_Sendmail();
$sendmail->setTimeout(3); //3 seconds
$swift =& new Swift($sendmail);
if ($foundit==1){
// pick up the id of content and collecting content of email
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "content";
$sql2 = "SELECT * FROM $table WHERE id = '$myid'";
$results2 = mysql_query($sql2) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results2)) {
$title = $row["mysubject"];
$mycontent = $row["mycontent"];
$myattach = $row["myattach"];
$myfilename = $row["attfile"];
echo"<br>CONTENT $title, $mycontent, $myattach, $myfilename";
}
// I now have the contents of the email so lets get the addresses for the cat
if( $myattach=="y") {
//there is a file to attach $myfilename = $row["attfile"];
$file_path = " /home/addictive/public_html/mailattachers/";
$file_name = $myfilename;
$full_file_path = "/home/addictive/public_html/mailattachers/".$file_name;
$file_type = "application/msword";
// echo"<br> $full_file_path";
}
//Everything looks ok, we can start Swift
//let them unsubscribe
$closing ="\n\nIf you wish to remove yourself from this mailing list at any time use the following link:\nhttp://www.pcpluton.com/unsubscribe.html\n\nThank you!\n\n";
$mycontent = $mycontent.$closing;
// strip slashes
echo"<br>THE CONTENTS email $mycontent";
$body = stripslashes ($mycontent);
$sender =& new Swift_Address($email, $name);
$table = "mailouts";
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$sql3 = "SELECT * FROM $table WHERE cat = '$mycat'";
$results3 = mysql_query($sql3) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results3)) {
$sendout = $row["myaddress"];
$yourname = $row["myname"];
//Create the sender from the details we've been given
//Create the message to send
$message =& new Swift_Message($yourname." ".$title);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($full_file_path), $file_name, $file_type));
}
//Try sending the email
//var_dump($sendout); var_dump($sender);
$sent = $swift->send($message, $sendout, $sender);
//Disconnect from SMTP, we're done
}
}
}
}
if ($foundit==1) {$swift->disconnect();}
if ($sent)
{
// header("Location: success.php");
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table="alldone"; $x = 1;
$today =date("Ymd");
$sqlC = "UPDATE alldone SET mydate='$today', catcompleted = '$mycat' , b2='$newtime' WHERE b1='$x'";
$myresultZ = mysql_query($sqlC) or die("An error ocurred :".mysql_error());
$table = "categories";
$full = "FULL";
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$sqlA = "SELECT * FROM $table WHERE mycounter != '$full'";
$resultsA = mysql_query($sqlA) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($resultsA)) {
$finalcat = $row["cat"];
}
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$yes="dead";
$today =date("Ymd");
$sqlx = "UPDATE $table SET status = '$yes', enddate = '$today' WHERE cat = '$finalcat'";
$resultsx = mysql_query($sqlx) or die("An error ocurred :".mysql_error());
$newcat=$mycat+1;
//Update control set cat = '$newcat' where id = '$myid'
require_once ("/home/addictive/public_html/control/hideit/connect.inc");
$table = "control";
$sqlx = "UPDATE $table set cat = '$newcat' where id = '$myid'";
$resultsx = mysql_query($sqlx) or die("An error ocurred :".mysql_error());
mail("ros@successuk.com", "PHP Script is done for $cat", "Finished on " . date("m j, Y g:i a"));
exit();
}
else
{ echo"sending_failed";
exit;
// header("Location: form.php?error=sending_failed");
//exit();
}
It now will only do a loop every 65 mins, except I am still getting the error
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 251346 bytes) in /home/addictive/public_html/control/mylib/Swift/Events/CommandEvent.php on line 49
even though the attachment is 179kb and the spurt is now only max of 50 but it does 10 before it dies.....How could I redirect it to use a temp file on my space??? and would this help? (do I assume the 16777216 bytes is the total size of the mail allowed to sendmail)??
solved
Posted: Tue May 15, 2007 4:52 am
by roscoe
I have turned on the cache again and this time changed the tmp directory as you suggested:
Code: Select all
Swift_Cache_Disk::setSavePath("/home/addictive/public_html/control/tmp");
making it of course chmod 777 to write to it.
So this works for large and small blats of 50 per time. Thanks very much for your help.
I found the info elsewhere on the forum after some hunting.
Maybe it is one of those "issues" which will keep repeating so should be on a sticky on the front of the forum as should the sendmail , smtp and possibly the reminder to use the correct version for php lol!
Now if only I can remember enough perl to add email addresses from a form going to perl, we will be done and dusted.