I know that by its very definition, a fatal exception should kill execution and should not be suppressed, but this is the problem.
I run a script that flushes, parses and stores about 10,000 pages in the database. This takes a couple of hours, and in rare cases (1 out of 1000) the page does not parse and throws a fatal exception.
I am currently doing this:
for ($i=0;$i<$count;$i++) { $classObject = $classObjects[$i]; echo $i . " : " . memory_get_usage(true) . "\n"; $classDOM = $scraper->scrapeClassInfo($classObject,$termMap,$subjectMap); $class = $parser->parseClassInfo($classDOM); $dbmanager->storeClassInfo($class); unset($classDOM,$class,$classObject); }
Can i do something like
for ($i=0;$i<$count;$i++) { $classObject = $classObjects[$i]; echo $i . " : " . memory_get_usage(true) . "\n"; try { $classDOM = $scraper->scrapeClassInfo($classObject,$termMap,$subjectMap); $class = $parser->parseClassInfo($classDOM); $dbmanager->storeClassInfo($class); unset($classDOM,$class,$classObject); } catch (Exception $e) {
The code above does not work for fatal exceptions .
Can I do something like this: If I move the main loop to a method and then call the method from register_shutdown_function ?
Like this:
function do($start) { for($i=$start;$i<$count;$i++) { //do stuff here } } register_shutdown_function('shutdown'); function shutdown() { do(); }
This is the message that appears when execution stops:
Fatal error: Call to a member function find() on a non-object in ...
I expect this above when the page is not parsed by the method I use. I'm fine just skipping this page and moving on to the next iteration of the loop.