I'm facing with the Fatal error: Maximum execution time of 30 seconds exceeded.  I'm trying to catch this error and show the error message to user but it seems that "try...catch..." in PHP can't handle this.  I have tried to use "register_shutdown_function" but not success, the script continue to run and display blank page.  $max_execution_time = ini_get("max_execution_time"); ini_set('display_errors', false); ini_set("max_execution_time", $max_execution_time * 0.8); register_shutdown_function([$this, 'shutdownHandler']);   ...  function shutdownHandler() {     $error = error_get_last();     if (($error['type'] === E_ERROR) || ($error['type'] === E_USER_ERROR)) {         ...     } }   Would anyone help me in this case?
5634
I can use set_error_handler() to catch most PHP errors, but it doesn't work for fatal (E_ERROR) errors, such as calling a function that doesn't exist. Is there another way to catch these errors?  I am trying to call mail() for all errors and am running PHP 5.2.3.
73749
I am doing a tutorial and am getting this error:     Fatal error: Class 'MySQLi' not found (LONG URL) on line 8   The code on line 8 is:  $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name);   I saw online someone said to see if it was turned on in my phpinfo(), but there wasn't anything listed in there under for "mysqli".  Also, I am running PHP version 5.2.5
89923
Question:  Is exception handling in Java actually slow?  Conventional wisdom, as well as a lot of Google results, says that exceptional logic shouldn't be used for normal program flow in Java.  Two reasons are usually given,   it is really slow - even an order of magnitude slower than regular code (the reasons given vary),     and    it is messy because people expect only errors to be handled in exceptional code.     This question is about #1.  As an example,  describes Java exception handling as "very slow" and relates the slowness to the creation of the exception message string - "this string is then used in creating the exception object that is thrown. This is not fast."  The article  says that "the reason for this is due to the object creation aspect of exception handling, which thereby makes throwing exceptions inherently slow".  Another reason out there is that the stack trace generation is what slows it down.  My testing (using Java 1.6.0_07, Java HotSpot 10.0, on 32 bit Linux), indicates that exception handling is no slower than regular code.  I tried running a method in a loop that executes some code.  At the end of the method, I use a boolean to indicate whether to return or throw.  This way the actual processing is the same. I tried running the methods in different orders and averaging my test times, thinking it may have been the JVM warming up.  In all my tests, the throw was at least as fast as the return, if not faster (up to 3.1% faster).  I am completely open to the possibility that my tests were wrong, but I haven't seen anything out there in the way of the code sample, test comparisons, or results in the last year or two that show exception handling in Java to actually be slow.  What leads me down this path was an API I needed to use that threw exceptions as part of normal control logic.  I wanted to correct them in their usage, but now I may not be able to.  Will I instead have to praise them on their forward thinking?  In the paper , the authors suggest that the presence of exception handlers alone, even if no exceptions are thrown, is enough to prevent the JIT compiler from optimizing the code properly, thus slowing it down.  I haven't tested this theory yet.
29690
I'd like to capture the output of  to a string.  The PHP documentation says;     As with anything that outputs its result directly to the browser, the  can be used to capture the output of this function, and save it in a string (for example).   What would be an example of how that might work?  print_r() isn't a valid possibility, because it's not going to give me the information that I need.
64738
I have a php script on a server to send files to recipents: they get a unique link and then they can download large files. Sometimes there is a problem with the transfer and the file is corrupted or never finishes. I am wondering if there is a better way to send large files  Code:  $f = fopen(DOWNLOAD_DIR.$database[$_REQUEST['fid']]['filePath'], 'r'); while(!feof($f)){     print fgets($f, 1024); } fclose($f);   I have seen functions such as  http_send_file http_send_data   But I am not sure if they will work.  What is the best way to solve this problem?  Regards erwing
92894
My computer is taking a very long time to shutdown.   How can I identify the culprit? I don't want to wait minutes for my computer to shutdown...  Is there a program I can use to track how long it takes to shutdown?
33203
What exception should I throw if I encounter an illegal state - for instance, an initialization method that should only be called once being called a second time?  I don't really see any built-in exception that makes sense.  This seems like something that should be in the framework - am I not poking in the right spot?
83646
I'm attempting a mass update on Contacts via Execute Anonymous. My code gives me the following error:     System.LimitException: Apex CPU Time Limit Exceeded   Here's my code:  List &lt;Contact&gt; contactList = [select Id, Mass_Update_Checkbox__c from Contact Limit 1000];  for (Contact contact : contactList) {     contact.Mass_Update_Checkbox__c = TRUE;  }  update contactList;
78348
You can do this in Python, but is it possible in PHP?  &gt;&gt;&gt; def a(): print 1 ...  &gt;&gt;&gt; def a(): print 2 ...  &gt;&gt;&gt; a() 2   e.g.:  &lt;? function var_dump() {} ?&gt; Fatal error: Cannot redeclare var_dump() in /tmp/- on line 1
94738
Whilst analysing some legacy code with FXCop, it occurred to me is it really that bad to catch a general exception error within a try block or should you be looking for a specific exception.  Thoughts on a postcard please.
44387
I am looking for good ideas for implementing a generic way to have a single line (or anonymous delegate) of code execute with a timeout.  TemperamentalClass tc = new TemperamentalClass(); tc.DoSomething();  // normally runs in 30 sec.  Want to error at 1 min   I'm looking for a solution that can elegantly be implemented in many places where my code interacts with temperamental code (that I can't change).  In addition, I would like to have the offending "timed out" code stopped from executing further if possible.
33494
I have the following code making a GET request on a URL:  $('#searchButton').click(function() {     $('#inquiry').load('/portal/?f=searchBilling&amp;pid=' + $('#query').val());             });   But the returned result is not always reflected. For example, I made a change in the response that spit out a stack trace but the stack trace did not appear when I clicked on the search button. I looked at the underlying PHP code that controls the ajax response and it had the correct code and visiting the page directly showed the correct result but the output returned by .load was old.  If I close the browser and reopen it it works once and then starts to return the stale information. Can I control this by jQuery or do I need to have my PHP script output headers to control caching?
16923
In your opinion, is it ever valid to use the @ operator to suppress an error/warning in PHP whereas you may be handling the error?  If so, in what circumstances would you use this?  Code examples are welcome.  Edit: Note to repliers. I'm not looking to turn error reporting off, but, for example, common practice is to use  @fopen($file);   and then check afterwards... but you can get rid of the @ by doing  if (file_exists($file)) {     fopen($file); } else {     die('File not found'); }   or similar.   I guess the question is - is there anywhere that @ HAS to be used to supress an error, that CANNOT be handled in any other manner?
9169
I want to see the stack trace in any function of my code, so i made somthing like this to call it and print the stack trace:  public function PrintStackTrace() {     try {         throw new Error('StackTrace');     } catch (e:Error) {         trace(e.getStackTrace());     } }   I like to know if there are other way to do this. In some place, the Error class creates the stack trace, but maybe it didn't do it with ActionScript 3.0 so maybe it's not posible, but i want to know.  Thanks!
17861
How would I validate that a program exists, in a way that will either return an error and exit, or continue with the script?  It seems like it should be easy, but it's been stumping me.
61575
It's a shame to type out an entire question, press post and then:     Sorry, you are only allowed to ask 50 questions in a 30 day period   Could you put some sort of notice on the page itself before submitting it to let you know the question won't be going through?  Or perhaps tell me how many questions I've asked in the last 30 days if it's >0?  Edit  This is not a complaint or statement about the limit, just a request that the error handling be done in a slightly better way to save people a lot of time.
70961
I am looking for a method built-in to ubuntu that will allow me to run a script or program or whatever for a fixed period of time.  , but the package is unavailable for Ubuntu. In any case, I was hoping for something built-in.  The only thing i can think of is to get the current time and set a cron job 30 minutes from 'now' that will kill the program.  I was hoping there was a way to do this without setting up a script, but if I need to - it wont be the end of the world. After the 30 minute interval I would like to put my laptop in a sleep mode, but this can be separate from the timer thing.  Thanks in advance.