2

So i was putting a WordPress website live the other day and when i did so, it crashed WordPress.

The culprit was file_get_contents(). I have been using it in a few small places to load my svg inline. See the code for how i was rendering it:

echo file_get_contents( get_bloginfo('template_url') . 'Images/logo.svg');

It worked fine on my local ubuntu apache set up and also worked fine on our staging servers which mimic the live environments.

Using a resource path instead of the web protocol path fixed the issues but isn't file_get_contents() also able to work with web resources?

Why did it happen only on the live when the staging server is the same?

Second issue (maybe related): The client whom I made the website for got their IT guy to point his A WWW towards our server, when he did and told me he had done it, i visited the site but also bought down my dedicated server and my hosting provider as well as the hosting company of the previous website!

There was a lot of traffic coming from the previous web host ip address to request the logo.svg. Does anybody have a good guess at whats happening here?

Blackbam
  • 17,496
  • 26
  • 97
  • 150
Freddie
  • 736
  • 5
  • 16

2 Answers2

1

There may be various reasons for this behaviour. First of all you in your wp-config.php you should

define('WP_DEBUG',true);

in order to see error messages correctly.

As you have already stateted file_get_contents() is able to work with web resources as well as with paths (http://php.net/manual/en/function.file-get-contents.php).

The fact that the problem is solved if you are using paths limits the amount of possible errors.

Possible problems with file_get_contents() and (possibly external) URLs are well known - have a look at the following discussions:

file_get_contents is not working for some url

PHP ini file_get_contents external url

Why doesn't file_get_contents work?

With your problem description there is no possibility to answer the problem more specifically. There can be a lot of different problems which result from the server configuration.

Blackbam
  • 17,496
  • 26
  • 97
  • 150
0

Looking at your code, you're making an HTTP request to your own server, use the local path to load the file instead.

echo file_get_contents( get_stylesheet_directory() . 'Images/logo.svg');
Tony
  • 859
  • 1
  • 7
  • 19