bryman79 bryman79 - 3 years ago 91
Ajax Question

XAMPP Issue When Including PHP File Located Outside DocumentRoot

I am running XAMPP (version 7.0.18) on a Windows 10 machine. I have a folder named “site” located on my desktop which contains the “DocumentRoot” folder. The path for the "DocumentRoot" folder is set in the httpd.conf file:

DocumentRoot "C:\Users\Username\Desktop\site\DocumentRoot"
<Directory "C:\Users\Username\Desktop\site\DocumentRoot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted

I am attempting to use AJAX in an HTML file in the "DocumentRoot" folder to return a response from a PHP file. It works fine if the PHP file is located in the “DocumentRoot” folder, but does not work if it is located outside the “DocumentRoot” folder (at say C:\Users\Username\Desktop\site\includes) and included by another PHP file located in the “DocumentRoot” folder. For example, I tried the following include_path set in the php.ini file:

include_path = ".;c:\Users\Username\Desktop\site\includes"

Despite error_reporting being set to E_ALL in the php.ini file, the only error returned is via the PHP error log (seems to be related to a script timeout - memory_limit set to 1M to reduce the amount of time before the PHP error is presented):

“PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 4096 bytes) in C:\Users\Username\Desktop\site\DocumentRoot\test.php on line 1.”

Removing/renaming the PHP file from the includes folder and removing/renaming the includes folder itself have no effect on the error. I would expect to see some error stating that the file or directory could not be found, but there is none.

I am new to XAMPP and cannot figure this out. Although I haven’t tried this exact situation on a production server, I have used AJAX in the past with no such issues on production servers. Any suggestions would be appreciated.


The PHP file in the “DocumentRoot” folder ("test.php"), which is attempting to include the PHP file outside the “DocumentRoot” folder ("test-process.php"), has the following on line 1:

<?php include 'test-process.php'; ?>


I tried using "include_once" (instead of "include") in the "test.php" file and no errors are given. So perhaps the "Allowed memory size..." error is caused from attempting to repeatedly include the "test-process.php" file.

But I still do not understand why no errors are given. I can even change the include_path to something that does not exist and no errors are given.


In response to the comments, the "test.php" and "test-process.php" were created as a simple test case. As noted in "Update 1" above, the "test.php" file has only a single line of code with an include statement. The "test-process.php" file has the following to return a message as JSON:

$output['message'] = 'Hello World';
echo json_encode($output);

Answer Source

It turned out that I had inadvertently left a copy of the "test.php" file in the root directory named "test-process.php," so it was continually running the include statement until the memory limit was reached.

Two possible solutions:

  1. Delete the "test-process.php" file (with the include statement) from the root directory
  2. Change the include_path set in the php.ini file to exclude the root directory:

    include_path = "c:\Users\Username\Desktop\site\includes"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download