JamesPy JamesPy - 3 months ago 25
Apache Configuration Question

apache php javascript - Failed to open stream: No such file or directory in /var/www/html/bla

I hope some bright spark can help me here. I have a site I am building, on an apache web server (Raspberry Pi 2). I am coding the site in php.

has a div that is refreshed using a simple jQuery script I wrote.

includes /include/start/times.php

includes /functions/time_func.php that calls a function to display live times in the index.php div.

The jQuery refreshes every 10 seconds.

When I first load the page, the div displays correctly.
When the jQuery runs 10 seconds later, the div is filled with the error in the title. I also get this error below:

Warning: include(): Failed opening 'functions/times.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')

I have looked at server permissions, and everything else I can think of. I'm hoping someone can help me this is causing me so much frustration now.

Interestingly, if I dump all the relevant files in my website root, and modify the inclusion paths, it all works fine :-/

Here are some file contents:


<head lang="en">
<meta charset="UTF-8">
<link href="css/style.css" rel="stylesheet">
<script src="js/jquery-2.1.3.min.js"></script>
function updateLeft() {
var url = "include/start/times.php";
setInterval("updateLeft()", 5000);
<body style="overflow-y: hidden;">
include 'include/start/times.php';


<div id="left">
<p class="no-margin text-shadow">Times: <br><br><span class="text-bold" id="pressure">
include 'functions/time_func.php';



// Define the cURL function
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20160904 Firefox/4");
$page = curl_exec($ch);
return $page;

function times(){
$x_data = curl("http://mysite.james.com/test_sceh.html");
$doc = new DOMDocument();
$sec1 = $doc->getElementsByTagName('td')->item(0);
$time1 = $doc->getElementsByTagName('td')->item(4);
$sec2 = $doc->getElementsByTagName('td')->item(6);
$time2 = $doc->getElementsByTagName('td')->item(10);
$sec3 = $doc->getElementsByTagName('td')->item(12);
$time3 = $doc->getElementsByTagName('td')->item(16);
$xtime = $sec1->nodeValue . ' - ' . $time1->nodeValue . '<br>' . $sec2->nodeValue . ' - ' . $time2->nodeValue . '<br>' . $sec3->nodeValue . ' - ' . $time3->nodeValue . '<br>';


It happens because the paths don't get resolved the same way.

When you load the page for the first time, it all starts from index.php I guess 'functions' is at the same level as include

When your include paths are relative, they are relative to the ancestor. So, relative to index.php when you load the page, but relative to times.php when you do your ajax request.

Because functions is not a subfolder of include/start, it fails to find the time_func.php

For this kind of scenario, where the same files are included from different parent folders, you should use an absolute path.

Something like:

<?php include $_SERVER['DOCUMENT_ROOT'].'/include/start/times.php'; ?>


<?php include $_SERVER['DOCUMENT_ROOT'].'/functions/time_func.php'; ?>

Or course, don't change the relative path you use in var url, it needs to remain relative to the root of the hostname.