<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Example that shows the effect of scream</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="scream.examples.html">Examples</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.weakref.html">Weakref</a></div> <div class="up"><a href="scream.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="scream.examples-simple" class="section"> <h2 class="title">Example that shows the effect of scream</h2> <p class="para"> This example demonstrates how scream affects the behaviour of PHP's error handler. </p> <p class="para"> <div class="example" id="example-546"> <p><strong>Example #1 Enabling and disabling scream at runtime</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Make sure errors will be shown<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'display_errors'</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">error_reporting</span><span style="color: #007700">(</span><span style="color: #0000BB">E_ALL</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Disable scream - this is the default and produce an error<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'scream.enabled'</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Opening http://example.com/not-existing-file\n"</span><span style="color: #007700">;<br />@</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.com/not-existing-file'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Now enable scream and try again<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'scream.enabled'</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Opening http://example.com/not-existing-file\n"</span><span style="color: #007700">;<br />@</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.com/another-not-existing-file'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Opening http://example.com/not-existing-file Opening http://example.com/not-existing-file Warning: fopen(http://example.com/another-not-existing-file): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in example.php on line 14 </pre></div> </div> </div> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> Usually one would set this in the <a href="configuration.file.html" class="link">php.ini configuration file</a> instead of changing the code. </span> </p></blockquote> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="scream.examples.html">Examples</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.weakref.html">Weakref</a></div> <div class="up"><a href="scream.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>