954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to force include/require to reload latest verion

I have a situation where I am updating a config file and I need a following include('config.php') to pick up the latest version of the file.

Presently what I am getting is that the include picks up the previous version that had been included earlier.

Here the scenario
index.php:

<?php
include_once('inc1.php');
...
include('inc2.php');
?>


inc1.php:

<?php
	$fname = 'inc2.php'; 
	require($fname);
	
	$handle = fopen($fname, 'w');
	fwrite($handle, "<p><?php echo 'in inc2 - written on ".date('Y-m-d H:i:s:u')." - now it is '; echo(date('Y-m-d H:i:s:u'));"."?></p>\n");
	fclose($handle);
?>


and in inc2.php (original):

<h1><?php echo 'in inc2'; ?></h1>


so what you have is that the first include_once of inc1 forces the include of inc2, which then gets updated. But when back in the main page, the include of inc2 now just brings the version that was loaded at the top of inc1, not the updated version.

Thanks,
Alain

apicard80
Newbie Poster
1 post since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You