7
votes

I wrote a simple crawler using Simple HTML Dom Parser to scrape some stuff.

It's a simple script only running with 1 process and nothing massive. But after some time it produces a "Segmentation fault (core dumped)"-error, when I am running it in the shell.

When I run the script in the browser it says

"Error: The connection to the server was reset while the page was loading.".

I have made sure to unset() every variable as soon as possible and also increased the memory_limit in php.ini, but still I get this error :/

Does someone know what it means and how to solve it?

Thanks for any suggestions!

5
en.wikipedia.org/wiki/Segmentation_fault That would be a crash of PHP itself (or one of its extensions), rather than a fault in your code. - Michael Berkowski
Interesting, thanks! I always wanted a good reason to finally start with Java and stop using PHP :) - Crayl
@MichaelBerkowski He should also know that the crash is most likely because of his code, even though it is the language's fault that it crashed instead of showing an error. Also Crayl: You will find Java is generally more difficult as a server-side script than PHP, so don't switch to if if you're looking for an easy fix. - Dave
@Dave Also interesting, thanks. Could also be caused by my code, because it got alot better since I have unset() all variables as soon they weren't needed anymore. - Crayl
Bear in mind that there is often a different, separate, php.ini file for command-line PHP; are you sure you're changing the memory_limit in the right file? (Try dumping ini_get('memory_limit'); in your script to double-check.) Also, if it's a memory leak that's causing the problem, which sounds the likeliest candidate, we'll need to see the script to know what's going on. - Matt Gibson

5 Answers

7
votes

I have this problem when a made a recursive loop by accident, so it runs out of memory. But the way it tells me is by making a Segmentation fault (core dumped) error!

So look a the code you most recently wrote and check if you made a error like this! My example was very simple (and stupid). I was just a little to fast to accept the autocomplete's suggestion :)

public function getAttendees()
{
    return $this->getAttendees();
}

Hope this can help someone in the future

2
votes

If anybody else has the same problem with Simple HTML Dom Parser: In this case the error was caused because of too long webpages. SHDP has a preconfigured "MAX_FILE_SIZE". You have to increase it in the source of simple_html_dom.php. See line:

define('MAX_FILE_SIZE', 600000);
2
votes

I've had it because free HDD space in VM ended due to too much data in /tmp folder

1
votes

The 'core dumped' I think just means the program released the memory and exited.

A segmentation fault usually occurs when you try and access a part of memory that is not yours to use, or by deferencing an uninitialised or invalid pointer.

Could you be passing/using a bad handle or overrunning an array somewhere?

-5
votes

I just has same issue. I was doing

return $var;

Which caused the error. However returning

return [$var][0];

worked. I'm sure there is a good explanation for this but I don't know it.