Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include() and require() occasionally don't work

Status
Not open for further replies.

rycrostud

Programmer
Jul 9, 2001
4
GB
My site is hosted on a Cobalt Raq3 server running PHP 4.0.6. I'm having some problems with PHP include() and require() commands.

Most of the time a page will load without any problem, but occasionally the include file isn't included before the HTML is served to the browser.

For instance my /includes/config.php file contains settings like the path to the images directory and my /includes/header.php file contains a link to an external style sheet.

When the include files are not included correctly none of the images load and none of the styles are applied.

Strangely, sometimes a portion of the include file will be there and sometimes none of it.

Has anybody else experienced this problem? Is it a known issue with Cobalt servers? Or am I doing something really dumb?
 
Show some example code, where you use these functions.
 
This is the code that I have at the top of my index page:

<?

require('includes/config.php');

$title = HOME_TITLE;

include('functions/functions.php');

include('includes/header.php');

include('newsnav.php');

?>

Here's the contents of my header.php include file:

<html>
<head>

<title><? echo $title ?></title>

<script language='JavaScript'>

// JavaScript for cancel buttons takes user back to home page

function goHome() {
location='index.php';
}

</script>

<link rel='stylesheet' href='/nms/news.css' type='text/css'>

</head>

<body bgcolor=&quot;#FFFFFF&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot;>
<table width='600' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td background='/nms/images/header_back.jpg' align='right'>
<img src='/nms/images/header_front.gif'>
</td>
</tr>
</table>
 
That's one I've never heard before...

So, when the includes don't load properly, you get no error messages? Just some missing HTML? I've never heard of this happening before.

Is your site getting lots of traffic? The only thing I can think of is that maybe your system is running out of open filehandles. Some default installs of Linux only allow 1024, or 4096 open filehandles at any time. This may sound like plenty, but for every request to a page with 4 includes, you have just opened 5 filehandles, not to mention other files, such as session temp files, images, you-name-it, plus the httpd process, the log files, your database connection... It builds up fast.

Try looking at your apache error_log, and see if it sheds any light on the situation.

You can check your max filehandles and inodes by doing:

cat /proc/sys/fs/file-max
cat /proc/sys/fs/inode-max

Change them to a higher number with:

/bin/echo 8192 >/proc/sys/fs/file-max
/bin/echo 16368 > /proc/sys/fs/inode-max

This is not necessarily your problem, though. If you have a recent version of Linux, then it probably defaults to more generous limits. Do you know if the Raq3 is running kernel 2.2 or 2.4?

If your problem doesn't show up in any of the above, then I recommend you reinstall Apache and PHP. This kind of problem highlights my dislike of &quot;web appliance&quot; type servers, which are sold as a pre-configured black box. As I understand it, Cobalt tends to discourage users from recompiling software from source, but this is the best way to get Apache and PHP working right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top