f



Custom error-handling creates "500 internal server error"

Hi there,

For AJAX-calls I'm buffering my output, check for errors and if an error oc=
curred print a custom, json-formatted error message. If everything works as=
 expected, the buffered output is printed. I don't send any headers in my s=
cript, but for some reason if an error occurs and my buffering's on, I get =
a "500 (Internal Server Error)" as response-header. If I switch off my cust=
om error-handling an the same error is thrown, PHP responds with a "200 OK"=
.. How can that be?

My code's this:

// Suppress normal error output
ini_set('display_errors', 0);

// buffer Output
ob_start();

// When the PHP-Script's ended check for errors an print buffered content o=
r an error message
register_shutdown_function(function() {=20

    $error =3D error_get_last();=20
   =20
    if($error) {
      ob_end_clean();
      header('Content-type: application/json');
      echo "{'some': 'json here'}";
    }else{
      ob_end_flush();
    }
   =20
});
0
6/10/2011 8:18:41 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

1 Replies
1335 Views

Similar Articles

[PageSpeed] 48

On 6/10/2011 10:18 AM, Luke wrote:
> Hi there,
>
> For AJAX-calls I'm buffering my output, check for errors and if an error occurred print a custom, json-formatted error message. If everything works as expected, the buffered output is printed. I don't send any headers in my script, but for some reason if an error occurs and my buffering's on, I get a "500 (Internal Server Error)" as response-header. If I switch off my custom error-handling an the same error is thrown, PHP responds with a "200 OK". How can that be?
>
> My code's this:
>
> // Suppress normal error output
> ini_set('display_errors', 0);
>
> // buffer Output
> ob_start();
>
> // When the PHP-Script's ended check for errors an print buffered content or an error message
> register_shutdown_function(function() {
>
>      $error = error_get_last();
>
>      if($error) {
>        ob_end_clean();
>        header('Content-type: application/json');
>        echo "{'some': 'json here'}";
>      }else{
>        ob_end_flush();
>      }
>
> });

http://nl2.php.net/manual/en/function.register-shutdown-function.php

Read it. :-)

Hint: Look up 'function' explanation:


=============================================
The shutdown function to register.

The shutdown functions are called as the part of the request so that 
it's possible to send the output from them. There is currently no way to 
process the data with output buffering functions in the shutdown function.
=============================================

Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens
0
6/10/2011 9:24:00 AM
Reply:

Similar Artilces:

Error using SOPC builder
I'm trying to make a SDRAM controller with SOPC builder, but when I change the data width to 8bits I get the following error.. Warning: Signal "az_be_n" of type "byteenable_n" and width 1 must have width of 2, 4, 8, 16, 32, 64, 128. I'm trying to make the system for a 64Mb SDR SDRAM, Micron MT48LC8M8A2P-75. Even when I select the Alliance AS4LC2M8S0-10 chip it does the same thing. So I'm guessing it has to do with a width of 8 bits. Thank you, Eric On Oct 18, 12:39 pm, sendt...@gmail.com wrote: > I'm trying to make a SDRAM controller with SOPC build...

file upload "500 internal server error" with filenames with commas
Hallo there just a simple script, i'm tring to upload a file from a form tag. If in the uploaded filename i have some aphostrophe or commas, i recive 500 error. HTML <form action='test.php' method='post' enctype="multipart/form-data"> <input id='photo' type='file' name='fhoto'> <input type="submit" value="Submit"> filename = tes't.jpg Any way to fix it ? Sandro On 10/1/2015 6:16 AM, Sandro Pellegrinetti wrote: > Hallo there > > just a simple script, i'm tring ...

Why is the difference between "Error Out.ctl" and "Error Out 3D.ctl"?
&nbsp; What is 'Error Out 3D.ctl' in LabVIEW 7.0? [It's found in 'Controls > Array & Cluster'.] Does it differ functionally from the old 'Error Out.ctl' found in 'Controls > Classic Controls > Classic Array & Cluster'? Or are the differences simply cosmetic? Neither of these controls seems to have an entry in LabVIEW Help. &nbsp; Oops - 'Why is' == 'What is' > Does it differ functionally from the old 'Error Out.ctl' found in > 'Controls > Classic Controls > Classic Array & Cluster'...

MAC SE: "Bomb" "Sys Error" / Address error" at start
Stephen Buggie (505) 863-2390 Psychology Department Univ. of New Mexico, Gallup February 15, 2006 200 College Road Gallup NM 87301 buggie@unm.edu NEED RESCUE DISK! MAC SE -- BOMB System Error / Address Error ------------------------------------------------------------------------------------------------ Dear Macintosh experts, My Mac SE crashes at power-up. I gives the bell-chime, then it proceeds though the launch sequence. After showing two extension-icons, it crashes. Then a dialogue-box shows the BOMB icon with the message, SORRY, A SYSTEM ERROR HAS OCCURRED --- ADDRESS ERROR It never reaches the desktop; this crash occurs every time. The Mac SE has a 330 meg internal hard drive, System 6.x.x, and a 1.4 meg internal 3.5 floppy drive. There is a SCSI port but no internal CD reader. The b/w screen is extremely sharp in its focus. The computer worked fine until about a year ago, when I stupidly put a file in the wrong folder. It has crashed consistently ever since! It has an assortment of software on the hard drive, but I have backups of everything and am willing to reformat the entire hard drive if necessary to get the computer working again! If I can resurrect the computer, I hope to upgrade the system to System 7.0 or 7.1 . DONE SO FAR: Yes, I have launched it with shift-key down, to turn off the extensions, but it always crashes Ive also tried vari...

"Server Creation Error" when creating a COM server running Excel
When I try to create a COM server running Excel (h = actxserver('Excel.Application'), I get the following error: ??? Server Creation Failed: Not enough storage is available to complete this operation. Any ideas on how to get around this? I was interested in running macro within Excel from MatLab, so simply opening the file isn't enough. ...

ksdensity function
Hello all, I am currently facing some issues when I upgraded from Matlab7 to Matlab12 on my Win7 laptop. Problem#1: I seem to be missing the ksdensity function (part of stats toolbox). Ignoring problem#1, to quickly solve it, I copied the ksdensity.m file from my LINUX version and added it to my Win7. Problem#2: When running a code that used to work on Matlab7, Matlab12 gave me an error for the ksdensity function (see below) ------------------------------------------------------------------------------------------ Undefined variable "internal" or class "internal.stats.parseArgs". Error in ksdensity>parse_args (line 186) [u,m,kernelname,support,weight,cens,cutoff,ftype] = ... Error in ksdensity (line 114) [axarg,yData,n,ymin,ymax,xispecified,xi,u,m,kernelname,... ---------------------------------------------------------------------------------------- I'm afraid I have ran out of clue on what is happening. Is it due to the the m file being different in different platforms ie I cannot simply copy the linux version to windows. I suspect my Problem#1 is due to my network installation ie missing toolboxes or Matlab12 has oddly hidden toolboxes - so no quick fix there just yet. But assuming functions are transferable, what could that error above mean? Appreciate any advice. Many thanks, Felicia > I am currently facing some issues when I upgraded from Matlab7 to Matlab12 > on my Win7 laptop. Problem#1: I seem to be m...

Awstats "Internal Server Error"
Hi, Installed Awstats on my Webmin and FC4 machine. When I try http://machine.com/cgi-bin/awstats.pl I get (Internal Server Error). I checked error.log and found: [Fri Dec 22 07:26:58 2006] [error] [client ] Premature end of script headers: awstats.pl No idea how to fix this. Please help. Thanks. dMan In news:1166803687.437525.84790@73g2000cwn.googlegroups.com, dman4x4@gmail.com <dman4x4@gmail.com> wrote: > Installed Awstats on my Webmin and FC4 machine. When I try > http://machine.com/cgi-bin/awstats.pl I get (Internal Server Error). I > checked error.log and found: &...

What is "error 8"
I set up an external serial modem using the Red Hat GUI networking tool as a generic modem device. However, when I hit the "Activate" button, I get the message, "Failed to activate device with error 8." Where can I find what "error 8" means? Thanks. No one responded, but for the benefit of any other newbies who encounter this problem, here is the solution: I looked in the System Log and saw that the modem did not find a dial tone. I plugged in a phone line, and the "Activate" command worked fine. (I had not realized that "Activate" meant "Connect.") Crooked River wrote: > I set up an external serial modem using the Red Hat GUI networking tool > as a generic modem device. However, when I hit the "Activate" button, > I get the message, "Failed to activate device with error 8." Where can > I find what "error 8" means? > System error numbers can be found in /usr/include/asm/errno.h The only problem is that there is no assurance that that is what the program is displaying. #define ENOEXEC 8 /* Exec format error */ does not sound like what you are really getting. The best bet would be to look at the source of the program that is producing that error message. Unfortunately, the scattered shell scripts, programs, and whatnot concerned with networking, especially dial-up networking is a spaghetti mess, and if your ...

Runtime error "Internal error 02 WSLINST"
I am having problems with Runtime error "Internal error 02 WSLINST". It occurs under no particular situation in an application made with Clarion 5.5 H. I have been reading about it in this group, and found that there are three possible solution for it: Internal Error 02 : WSLINST RESPONSE 1 : This occurs when the threaded variable manager tries to swap in a threaded variable for which it has no saved value. It should never happen, and I don't know of any circumstance in which it does happen. If anyone has a reproducible instance of it (preferably small) I'd like to see it. Richard Chapman TopSpeed Corporation RESPONSE 2 : Carefully delete all compiler debris files, then recompile all code and components using the same Run Time Library property. RESPONSE 3 : To summarise : There is a bug in the intellimouse driver when running lots of programs under Winnt that (in theory) has been fixed with version 2.2a (document Q189770 at microsoft support) The workaround is to go to the list of apps that intellimouse should ignore and add Clarion to them. However, after trying these solutions, I have not solved the problem. Could anyone help me with this problem please? Is there new information about it? Is there any clarion patch to fix it? Thank you JUan S ...

LSM error "Internal volume daemon error"
Hi there, I'm rather new to tru64 so please, if I'm lacking detail here let me know. I have an existing DS10 box with tru64 v4.0f. We've ordered another box of identical specifications. I restored a backup of box1 to box2 (box2 is the new box). I then booted box2 and attempted to re-initialise LSM. The problem is I keep running into this error and it really means nothing to me. When ever I try to use a utility such as "volsetup" it reports "Internal volume daemon error". The box has all the licenses installed and is identical to its c...

"unknown mailer error 4" "unknown mailer error 32"
Hi Im running sendmail 8.12.9 on Solaris 8. I got "unknown mailer error 4" and "unknown mailer error 32". What does these messages mean ? Please teach me. Below is maillog. Jun 9 05:50:21 mailserver sendmail[21744]: [ID 801593 mail.info] h58Ke8TK021744: to="|/usr/local/majordomo/wrapper sequencer -l mailinglist -n -h localdomain mailinglist-outgoing", ctladdr=<mailinglist@localdomain> (1/0), delay=00:10:21, xdelay=00:10:13, mailer=prog, pri=48014, dsn=5.3.0, stat=unknown mailer error 4 Jun 9 05:51:24 mailserver sendmail[21744]: [ID 801593 mail.info] h5...

"Error: Windows API error 6: The handle is invalid"
I am using Windows XP v5.1 (Service Pack 1) on a GenuineIntel motherboard with a 500 MHx Pentium III processor. I try to install the basic version of MikTex 2.5 and get this error "Error: Windows API error 6: The handle is invalid" at the end of the installation. Can anyone suggest a fix? I am not committed to MikTeX, only to getting LaTeX working on my machine. Many thanks in advance, Peter. MajorSetback@excite.com wrote: > I am using Windows XP v5.1 (Service Pack 1) on a GenuineIntel > motherboard with a 500 MHx Pentium III processor. I try to install the > basic version of MikTex 2.5 and get this error > "Error: Windows API error 6: The handle is invalid" > at the end of the installation. Can anyone suggest a fix? I am not > committed to MikTeX, only to getting LaTeX working on my machine. > > Many thanks in advance, > Peter. I ran the installation again and it worked the second time. MajorSetback@excite.com writes: > MajorSetback@excite.com wrote: >> I am using Windows XP v5.1 (Service Pack 1) on a GenuineIntel >> motherboard with a 500 MHx Pentium III processor. I try to install the >> basic version of MikTex 2.5 and get this error >> "Error: Windows API error 6: The handle is invalid" >> at the end of the installation. Can anyone suggest a fix? I am not >> committed to MikTeX, only to getting LaTeX working on my machine. >> >> Many thanks in advan...

Awstats "Internal Server Error" problem
I have installed Awstats and configured it for my site "domain.com" the config file for stats is stored in /etc/awstats/awstats.domain.com.conf when i run the awstats script using perl awstats.pl -update -config=domain.com awstats executes and the output is as shown below: Update for config "/etc/awstats/awstats.domain.com.conf" With data in log file "/usr/access_log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 134771 Found 4 dropped records, Found 0 corrupted records, Found 0 old records, Found 134767 new qualified records. BUT when i try to see the result by checking http://localhost/awstats/awstats.pl?config=domain.com i get "Internal Server Error". I checked the http error logs and it says permission denied for exec to execute awstats.pl. Just for testing i chmod everything to 777. So that i shouldn't get the permission error. But inspite of changing i still get the same error. Whats the problem here?? Where is the Tug? This is the errror_log: [Fri Dec 15 04:21:44 2006] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Fri Dec 15 04:21:44 2006] [notice] jrApache[init] JRun 4.0 (Build 92909) Apache 2 module - Feb 18 2005 06:40:07 [Fri Dec 15 04:21:45 2006] [notice] Digest: generating secret for digest authenticatio...

Error: "Xlib: connection to ":0.0" refused by server"
Hi NG I have just installed CounterStrike on SuSE 9.0 When i try to run the program i get following error: // linux:/home/xx/.wine/fake_windows/Sierra/Counter-Strike # wine cstrike.exe Xlib: connection to ":0.0" refused by server Xlib: No protocol specified x11drv: Can't open display: :0.0 // Can u please help me Thanks SjeM <sm@ask.me> writes: > linux:/home/xx/.wine/fake_windows/Sierra/Counter-Strike # wine cstrike.exe > Xlib: connection to ":0.0" refused by server > Xlib: No protocol specified Can you run other X program...

'echo "": No such file or directory" error using "exec" to pipe in PHP script
[TCL] set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts [exec "echo '$php' | php -q"] [/TCL] When I try this within TCL I get the following error: [quote] echo "": No such file or directory [/quote] I am unable to be able to use the CLI PHP "php -r" option due to my PHP installations on various servers being CGI and not CLI SAPI, else, I would just do that, so I'm trying an alternative that is choking TCL. I am using a very simple example within the TCL $php variabl...

Trying to solve a python/mechanize "error 500" http error
i'm getting the following error: mechanize._response.httperror_seek_wrapper: HTTP Error 500: i'm running python 5.1 and mechanize 0.1.7b I have no idea as to what I have to change/modify/include to handle this issue. The link that I'm testing is at the bottom of the page. When I insert the link into the browser, I actually get an err page.. so, I suspect that there is a handler that I should be able to modify/use to handle this situation... Thoughts/Comments will be greatly appreciated... Thanks the output is: www = www.1800ink.com url2= http://www.quantcast.com/www.1800in...

"Error: Windows API error 6: The handle is invalid" #2
I am using Windows XP v5.1 (Service Pack 1) on a GenuineIntel motherboard with a 500 MHx Pentium III processor. I try to install the basic version of MikTex 2.5 and get this error "Error: Windows API error 6: The handle is invalid" at the end of the installation. Can anyone suggest a fix? I am not committed to MikTeX, only to getting LaTeX working on my machine. Many thanks in advance, Peter. ...

SQL Server 2005 DTS problem: "Error 21776: General Error"
I've recently migrated all databases to SQL Server 2005. I couldn't figure out how to create an SSIS package in the time I had, so I just stuck with the DTS packages. They all worked fine during testing, but once we renamed the server we had problems. The DTS packages still work, but whenever I click into the Copy SQL Server Object and try to Select Objects (on the Copy tab) I get this error: Microsoft SQL-DMO Error 21776: General Error I click OK and get the error again and again for a total of 12 times (regardless of which database I'm connecting to in the packages, so it's not related to the number of objects in the database). Then the Select Objects screen appears and it's business as usual. Has anyone else come across this problem and found a solution? I've renamed the server using sp_dropserver and sp_addserver and select @@servername returns the correct value John Hunter In the past I would script out the DB and then copy the data, but just restoring on 2005 from the 2000 backup files has worked flawlessly for this version upgrade on dozens of my production databases. I have never had much success using DTS for object transfers. <jshunter@waikato.ac.nz> wrote in message news:1173065296.527747.58960@c51g2000cwc.googlegroups.com... > I've recently migrated all databases to SQL Server 2005. I couldn't > figure out how to create an SSIS package in the time I had, so I just > stuck with the DTS packages. They all ...

An internal error occurred. Report the following error code : "0xFFFF8544". #2
On Window 2000 Professional Server DB2 UDB Level: DB2 code release "SQL07029" with level identifie "030A0105" and informational tokens "DB2 v7.1.0.98", "n040510" and "WR21337". In the db2diag.log, ---------------------------------------------------- 2005-12-20-10.05.43.278000 Instance:MC Node:000 PID:8504(db2syscs.exe) TID:8320 Appid:0A09F517.B197.051220160537 relation_data_serv sqlrl_sysTablesRead Probe:25 Database:UMCPROD DIA9999E An internal error occurred. Report the following error code : "0xFFFF8544". ...

activex error Error -2147417851 &quot;server threw an exception&quot;
Hello everyone.. I am stuck in an activex - excel issue and i need help. I have already tried most of the tips provided in the forum but still no luck.The problem is this: I have the attached vi, slightly modified, and it creates an excel, renames the sheet, on the next iteration it opens the previously created xls and adds another sheet and renames it. I get this error "Error -2147417851 occurred at The server threw an exception." but not always. Sometimes when i delete the file created to run the vi again, it works fine, on my second attempt i get the error again. Weird thing is that when i use the "highlight execution" debugger the problem disappears. I upgraded excel 2000 with SP3, i tried to insert a delay using Flat Sequence Structure but no luck. I tried the MS office homepage but nothing. If anyone can think of something to help please, please let me know.Labview 7.1, MS Excel 2000 SP3.Thanx in advance for your time guys..Yiannis not-ok.vi: http://forums.ni.com/attachments/ni/170/327397/1/not-ok.vi tough one eh?? &nbsp; &nbsp; &nbsp; The error comes from LabVIEW using many threads for the activeX objects; and setting it to run in the user-interface thread means that it will only use one thread to manage its activeX objects. Have you looked at this thread? <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=302498" target="_blank">http://forums.ni.com/ni/board/message?board.id=170&...

f$getsyi("hw_name") v. PWS 500a (was: "ftp server error")
From: "Craig A. Berry" <craigberry@mac.com.spamfooler> > > alp2 $ write sys$output f$getsyi( "hw_model") > > 1556 > > > > What does a real 500au say? > > Exactly the same as what you get. Also note: > > $ write sys$output f$getsyi( "hw_name") > Digital Personal WorkStation > > Though the docs to $getsyi say that SYI$_HW_NAME can return up to 60 > characters, the DPW names seem to be truncated at about 30 for some > reason. One more subtlety: ALP $ write sys$output ">"+ f$getsyi( &qu...

[compilation error] debugging this error message "Object() in java.lang.Object cannot be applied to"
Hi,I have a class called Device that instantiates another class DbMoneyin this manner:=== return new DbMoney( money, hardware.getName() );===1) Both are in the same package, i.e. my.IMoney & my.Device2) When I compile them, javac complains with the error:Object() in java.lang.Object cannot be applied to (my.IMoney,java.lang.String) return new DbMoney( money, hardware.getName() ) ^Q) My arguments to the DbMoney constructor match that of its declaredmethod parameters. So that can't be the problem. What am I doingwrong ?Gavin On Mar 28, 3:25 pm, "Gavin" <gavin.emp...@gmail.com> wrote:> Hi,G'day. Please note that starting a post'ssubject line with words in '['/']' will causethem to be hidden in the the GG groups list.I suggest not to do that, so everyone can seethe entire subject line.> I have a class called Device that instantiates another class DbMoney> in this manner:...> return new DbMoney( money, hardware.getName() );...> Object() in java.lang.Object cannot be applied to (my.IMoney,> java.lang.String)> return new DbMoney( money, hardware.getName() )> ^>> Q) My arguments to the DbMoney constructor match that of its declared> method parameters.Do they? Your code snippets do not supportthat, or more accurately, if we had an SSCCE*,we could confirm that for ourselves.>..So that can't be the problem. What am I doing> wrong ?...

vpn problems to win2k server error "Error 800: Unable to establish connection "
Hello everyone, I am trying to connect from win2kpro to small business server 2000 thru a vpn connection. I installed a second nic on my server and did the ICW and RRAS wizards and enabled ports 1723 and 47. I even did port fordwarding to thru the router(SMC 2804wbr) to forward direct to my server using first the external nic, then the internal nic, then both. and still nothing, I keep getting "Error 800: Unable to establish connection ". I looked in Support.microsoft.com, but was no help. The router is a wireless g router/ap combo and is definetely after 2000 and firmwa...

Why display error message that is "pthdb_session.c, 794: 53 PTHDB_INTERNAL (internal error)" ??
Found core file in Pro*C program on AIX 5.2.0.0. The Core file contents is as follows pthdb_session.c, 794: 53 PTHDB_INTERNAL (internal error) pthreaded.c, 1800: PTHDB_INTERNAL (internal error) Illegal instruction (illegal opcode) in . at 0x0 warning: Unable to access address 0x0 from core (dbx) where pthdb_session.c, 794: 53 PTHDB_INTERNAL (internal error) pthreaded.c, 1800: PTHDB_INTERNAL (internal error) warning: Unable to access address 0xfffffffffffffffc from core warning: Unable to access address 0xfffffffffffffffc from core warning: Unable to access address 0xfffffffffffffffc from cor...

Web resources about - Custom error-handling creates "500 internal server error" - comp.lang.php

New Facebook SDK For IOS Adds Automatic Error Handling, Improved Login UI
... software-development kit for iOS is now available for download , with significant enhancements including a beta test of automatic error handling ...

New Facebook SDK For IOS Adds Automatic Error Handling, Improved Login UI - SocialTimes
... software-development kit for iOS is now available for download , with significant enhancements including a beta test of automatic error handling ...

Facebook Updates SDK For iOS With Improved Analytics, Error Handling And More
Facebook has just released an update to its official software development kit (SDK) for iOS.

Credit Bureaus Agree To Revamp Practices For Handling Errors, Unpaid Medical Bills
... that over the next three years these credit reporting agencies (CRAs) must make nationwide policy changes regarding the ways they handle errors, ...

The Scourge of Error Handling
Return values and exceptions are both inadequate tools for handling errors. But we're stuck with them for the foreseeable future just as we ...

Taking Toddler Steps with Node.js – Express Error Handling
In the previous post I wrote about my personal routing flavor for Express . For this post, I want to briefly discuss how to set up error handling ...

Massive Facebook outage caused by improper error handling, not improper Facebook flirting as previously ...
This has not been a good week for social networking. First there was that security hole on Twitter's site, and yesterday time stood still (and ...


Swift and Cocoa Error Handling
I’ve not see much written about how to do real-world Cocoa error handling in Swift. That is, you’re calling Objective-C methods with NSError ...

FieldVal Tackles Lackluster API Error Handling
A new JavaScript library called FieldVal aims to solve some of the biggest problems associated with API error handling .

Resources last updated: 3/23/2016 4:09:54 PM