read php script from memory
Posted: Wed Jul 21, 2010 3:56 pm
I saw a php function which uses "php://temp" to read and write a "file" in memory. I wanted to write a bunch of PHP code to memory and then read it back from memory. Can I use php://temp to do so?
this works (using "shm" memory in Linux, not MS-Windows compatible):
this works: (using hard drive)
doesn't work:
I am testing the code using PHP 5.2.
Code: Select all
$somecode = "<? someFunction();
function someFunction(){
echo \"you successfully ran someFunction\";
} ?" . ">";Code: Select all
file_put_contents("/dev/shm/1.php", $somecode);
$fp = fopen('php://temp', 'r+');
include '/dev/shm/1.php';
Code: Select all
file_put_contents("1.php", $somecode);
$fp = fopen('php://temp', 'r+');
include '1.php';
Code: Select all
$allFunctions=fopen('php://temp', 'r+');fwrite($allFunctions,$array);rewind($allFunctions);//fclose($allFunctions);
include 'php://temp';