SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Fatal error: Maximum execution time of 30 seconds exceeded

    Hi, I need your help please,...I am using Swiftmailer in sending email,now what i need is how can i catch this "Fatal error: Maximum execution time of 30 seconds exceeded "...so that i can prompt this to the user.





    Code:
     try{
    
    
            $transport = Swift_SmtpTransport::newInstance('smtp parameter here')
    
                ->setUsername('username')
                ->setPassword('password')
            ;
    
            $mailer = Swift_Mailer::newInstance($transport);
          
                $message = Swift_Message::newInstance()
    
    
                    ->setSubject('this is the test')
    
    
                    ->setFrom(array($email=> "john"))
    
    
                    ->setTo(array($tosomeone)
    
    
                    ->setBody('hello','text/html');
    
               $mailer->send($message);
            
    
    
            }
    
            
    
    
    
        
    
        }
        catch(Swift_SwiftException $err){
            $failed = $err->getMessage();
        }
    Thank you

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    IMHO if you are exceeding 30 seconds of time ( a HUGE amount BTW) then it's not something the user needs to be concerned with - it's the programmer. You've got a loop or something in your code that is not doing what you expect

    I'm afraid I am not familiar with the type of syntax you are using in your code, so I can offer no solution, other than to say it's not the user's fault and he/she should never see this happening. You need to figure out why you are getting this error.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    try/catch won't get fatal errors. If it is this section of the code that's causing the issue, the problem likely is that it can't connect to the mail server and it times out. The solution there would be to make sure the firewall is not restricting you, the mail server is running properly, etc.
    - Robert

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the reply..

    Maybe this is the cause for my attachment the file size is 196kb file this will always raise to fatal error like i posted above...but if i will attach only 27.7kb,it succeeded send.

    Thank you in advance.

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,015
    Mentioned
    62 Post(s)
    Tagged
    0 Thread(s)
    You can change the maximum execution time allowed in the PHP.ini settings or using the htaccess file. Also consider using a cli script, which has no maximum execution time restriction (though this will need to be fired from a cron job and is tricky to set up).

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    IMHO this is a poor solution to the OP's problem. Thirty seconds of cpu time is not something that anyone should be running. It is a problem, not a "long running task", unless he is calculating planetary orbits or something.

    And - if I am not mistaken, the html file upload process occurs before the php script runs, therefore it does not impact the cpu time limit of a script. I could be wrong here tho.

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,014
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Although throwing more time or memory at a script might work, unless it's running on your localhost and you don't mind waiting (and even then) it's much preferable to fix the problem if you can.

    This is especially true if your on a shared host. They aren't likely to be pleased if you start hammering resources.

    Then again, if only a minor tweak is needed, it might be OK I suppose.

    Are you sure it's the file size? i.e. not doing multiple uploads/sends at the same time.

  8. #8
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,998
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    I noticed this when comparing the code from your post with how it is in the documentation:

    PHP Code:
    ->setFrom(array($email=> "john")) 
    Change that bit to:
    PHP Code:
    ->setFrom(array("$email=> 'John Doe')) 
    Give it a try once that change is made, did it make any difference to the execution time (better, worse or about the same)?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •