I am sort of new to Web programming, so this may be a real obvious thing...
I wrote a php script that runs on Apache/Linux, PHP 4. It is invoked from a FORM through a GET method. The script does quite a few things:
1) It downloads a file from another website through get_file_contents and saves it to the server
2) It preprocesses the file with some commands executed through system()
3) It sftps the file to another server
This process can take some time for large files - maybe a couple of minutes
For some reason, on certain machines that run Firefox, this script gets executed twice. IE seems to work fine. Also I have a Vista machine with Firefox and that seems to work fine as well.
How do I go about debugging this??
Thanks!
-Andy
php script sometime executes twice
Moderator: General Moderators
Here is the upload script
And here is how it gets invoked
On the browser screen I see
It looks to me like this gets displayed, and then when the script is executed again, the browser refreshes and displays it again.
I can tell the script is being executed twice because I get two timestamps in the log file.
Code: Select all
<?php
$fd = fopen("log2", "a");
// write string
$date = date("h:i:s a", time());
fwrite($fd, $date . "\n");
// close file
fclose($fd);
ini_set('memory_limit', '1024M');
session_start();
include 'config.php';
include 'opendb.php';
$video_string = trim($_GET['txtMovieURL']);
$video_file = file_get_contents($video_string);
$filename = "/home/andy/public_html/proto/" . $_GET['uploadFileName'] . ".flv";
$handle = fopen($filename,"w");
fwrite($handle, $video_file);
fclose($handle);
system('/home/andy/public_html/proto/flvtool.sh -U -metadatacreator:XXX ' . $filename);
$subst1 = "perl -pi -e 's/FILENAME/" . $_GET['uploadFileName'] . ".flv" . "/g' /home/andy/public_html/proto/batchfile";
system($subst1);
system('sftp -b batchfile b7@b7.com');
$subst2 = "perl -pi -e 's/" . $_GET['uploadFileName'] . ".flv". "/FILENAME/g' /home/andy/public_html/proto/batchfile";
system($subst2);
$video_insert_sql = "insert into videos(name) values(\"". $_GET['uploadFileName'] . "\")";
mysql_query($video_insert_sql) or die('Query failed. ' . mysql_error());
?>
<html>
<head>
<title>Main User Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Upload successful
<p><a href="main.php">Main</a> </p>
<p><a href="logout.php">Logout</a> </p>
</body>
</html>Code: Select all
<?php
session_start();
// is the one accessing this page logged in or not?
if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) {
// not logged in, move to login page
header('Location: login.php');
exit;
}
if (isset($_SESSION['user_id']))
{^M
echo date("h:i:s a", time());
echo "Welcome ", $_SESSION['user_id'];
}
?>
<html>
<head>
<title>Upload your video</title>^M
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="upload.php" method="get" name="frmUploadMovie" id="frmUploadMovie">
<table width="400" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">Enter Movie URL</td>
<td><input name="txtMovieURL" type="text" id="txtMovieURL"></td>
</tr>
<tr>
<td width="150">Enter Upload Filename</td>
<td><input name="uploadFileName" type="text" id="uploadFileName"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLoadMovie" type="submit" id="btnLoadMovie" value="Upload Movie"></td>
</tr>
</table>
</form>
<p> </p>
<p><a href="logout.php">Logout</a> </p>
</body>
</html>On the browser screen I see
Code: Select all
sftp> cd dir1 sftp> cd dir2 sftp> cd dir3 sftp> put beast5.flv Uploading beast5.flv to /b7/dir1/dir2/dir3/beast5.flv sftp> sftp> Upload successfulI can tell the script is being executed twice because I get two timestamps in the log file.