Forum Moderators: coopster
Question.
So does it look like this:
File1.php has a function labeled getSomething()
File2.php has a function labeled getSomething()
File3.php has a function labeled getSomething()
File4.php has a function labeled getSomething()
and your cron job is trying to distinguish between getSomething() from File1.php and getSomething() in File2.php?
You know, maybe renaming it is out of the question but, a simple search and replace to rename them would be like "go to each line, find the keyword 'function' and replace it with 'function file1'" for the file1.php functions and similar for file2.php, etc... Only problem is then calling you'll need to distinguish which ones you want called. Iono, I'm just tossing ideas out there :P
--Nick
That will execute the scripts as their own separate threads. If you need the response from the scripts, that's the return value of file_get_contents:
$r1=file_get_contents("http://example.com/scripts/script1.php");
$r2=file_get_contents("http://example.com/scripts/script2.php");
etc.
$n=1;
include ($script);
$n +=1;
I do like the idea of using
file_get_contents($script);
Yes unfortunately all the scripts have the same function names in them and they are all named the same in every script.
I didn't write the scripts I just have to use them as they were provided by a vendor. The scripts are for reading in xml and writing it to a MySQL database. this probably would explain the repetitiveness. Let me know if you have any more ideas.
especially something along the lines of the
file_get_contents($script);
runkit_function_remove(string $functionName);
Thanks to all of ya'll for your advice and guidance.
I do like the idea of usingfile_get_contents($script);which I tried but it doesn't seem to execute the script like an include does.
And you may be right - it is a different way that they are called - I was assuming they were essentially standalone scripts which you needed to 'execute' rather than includes which would be providing data or functions back to your main file.
Make sure you use the full HTTP path (http://....) not a server path or relative path.And you may be right - it is a different way that they are called - I was assuming they were essentially standalone scripts which you needed to 'execute' rather than includes which would be providing data or functions back to your main file.
They are each standalone scripts which I need to execute. But doesn't file_get_contents return the file in a string?
I may be a little confused here.
If it returns the contents of the file in a string then do I need to execute the string?
Let me make this a little easier I will post the cron script.
<?php
//set the file to read and move
$today = date("m-d-y");//connect to the database
dbx_connect();
$result = mysql_query("SELECT * FROM stats_files") or die(mysql_error());
while($row = mysql_fetch_array($result)){//set the variable using the database rows
$filename = $row['filename'];
$folder = $row['folder'];
$script = $row['script'];
$old_file = "$filename.xml";
$new_file = "$folder/$filename/$filename_$today.XML";// check to see if this particular file has been delivered tonight.
if (file_exists($old_file)) {//file found
echo "I found the file $filename <br/>";//execute the appropriate script
file_get_contents($script);
//include($script);
//move file to appropriate folder add date to name
//not working due to phpini permissions
//tried the ftp alternative and cried "No Joy"
//chown($old_file, nobody);
//chmod($old_file, 0777);
//rename($old_file, $new_file);}
else {echo "File $filename is not available <br/>";}
}//the only global function(I hope)
function dbx_connect() {
mysql_connect("********","********_********","********");
mysql_select_db("********_test");
}
?>
However, if you pass a complete URL (not path) i.e. starting with [......] then it will actually execute it and what is returned is the result of executing the script.
How wickedly awesome is that. I got it to work. I took and created a variable called $ran and made it a blank variable before the execution of the script. Then I ran the script equal to the variable. Last I echoed the output so I could see it.
//file found
echo "I found the file $filename <br/>";
$ran = "";
//execute the appropriate script
echo "$script <br/>";
$ran=file_get_contents($script);
//to see the output of the script
echo "$ran <br/>";
echo "$n <br/>";
$n += 1;
$n is just being used as a counter for the time being to keep track of things.
vincevincevince you are da man. Thank you also to all the other responses. I kind of used all of them to find the last solution.
One last question....
Can * be used as a wildcard character when you don't know the exact name of a particular file you want to access?
example: $file = "../my_STORY*.xml";
where the file name is always different after STORY.
the file name changes with a date stamp my_STORY$20070517213819080000201.xml
Thanks,
Can * be used as a wildcard character when you don't know the exact name of a particular file you want to access?
I used the opendir to list all the files in the directory, then I used a preg_match to find files that started with the exact wording that I wanted to use. After I found the files I then went ahead and ran the script for that particular file.
"Genius." "Genius I tell you."
Here is the part I added to find the files that I wanted.
//finding and running the stories as they have a dynamic name
if ($filename == "my_STORY"){
$path = "path/to/the/directory/that/holds/the/xml";
$dh = opendir($path);
$i=1;
while (($file = readdir($dh))!== false) {
if($file!= "." && $file!= "..") {//get only the files I want
if (preg_match("/my_STORY*/",$file)){
$filename = $file;
echo "$filename Was Found! <br/>";
$ran = "";//execute the appropriate script
echo "$script <br/>";
$ran=file_get_contents("$script?file=$filename");//to see the output of the script
echo "$ran <br/>";
echo "$n <br/>";
$n++;
}//to print out the contents of the whole directory
// echo "$i. <a href='$path/$file'>$file</a><br />";
$i++;
}
}
closedir($dh);
}
since I receive about 10 stories a night with these types of file names I had to do this.
my_STORY$20070517213819080000201.xml
my_STORY$20070517224752740000101.xml
my_STORY$20070518225828980000101.xml
my_STORY$20070518233807270000101.xml
I hope this can help someone else trying to do this type of thing.
Drunk