Internal Server Error: strpos(): Empty needle

Linode Staff

When we navigate to one of our website pages, we receive the following error message:

Internal Server Error
strpos(): Empty needle

What can we do to make this error go away and make the page accessible again?

2 Replies

Internal Server Errors can be rather frustrating to deal with because they often lack descriptive information about the cause of the error. You can read about a few causes in the following Community site post:

500: Internal Server Error

When you run into this type of error, it's basically telling you that there is something wrong on the server side of things. From there, it's usually best to review your web server logs for additional clues.

In this case, it appears that you received a unique error message (strpos(): Empty needle) that may provide insight. I haven't personally encountered this error before, but it appears to be related to the strpos string function in PHP.

From the PHP documentation I linked above, it looks like this function allows you to find the position of the first occurrence of a substring in a string. If you look over the Parameters section, you'll see that the function requires a few parameters. The haystack parameter is the string you're searching in, and the needle parameter is substring you're looking for.

The error you received seems to indicate that the needle parameter is empty in the function you're using on your website, so you'll likely want to take a look at the strpos function in the relevant php file to spot the exact issue.

Hope this gets you started!

If your project uses composer ( https://getcomposer.org ), you can do this…

  • Add this to your composer.json file:
{
    "require": {
        ...,
        "filp/whoops": "^1.1",
        ...
    }
}
  • Run composer update.

  • In your index.php, add the following somewhere near the top (but after you require "autoload.php"):

 $whoops = new \Whoops\Run;
 $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
 $whoops->register();

Now, when stuff like this happens, you'll get a nice tombstone in your browser with a backtrace. Once you're done debugging/testing, you can comment out the 3 lines in index.php to return to the way you were (it's ok to leave the composer.* files the way they are).

See https://github.com/filp/whoops

DANGER WILL ROBINSON!!! DANGER! DANGER!

Doing this may expose other bugs in your code you didn't know were there. PHP does a lot of stuff silently that a lot of coders take for granted. I don't suggest doing this on a production site.

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct