PHP - Why Does It Take So Long To Recognize File Existence?
I'm working on a website that displays data based on when a file is created. The page keeps checking to see whether or not a file exists. As long as the file doesn't exist, the page keeps reloading and checking to see whether or not the file exists until the file finally does exist. Once the file exists, the page goes to another page that displays the contents of the file that it was waiting for.
This design works, but I've noticed that it takes a long time for the page to recognize that the file exists. Once the file exists, the page keeps checking and reloading, several times -- even though the file exists. After many reloads, it finally "sees" the file and goes on to the next page. Why does it take so long for my page to recognize the existence of the file? Here's a sample of how the reloading page (the page that keeps checking for the existence of the file) works. <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past session_set_cookie_params(0); session_start(); ?> <html> <head> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'> </head> <body> <p>Processing...</p> <script> myFunction(); function myFunction() { setInterval(function(){ location.reload(); <?php clearstatcache(); if(file_exists($_SESSION['filename'])) { $existance = true; } else { $existance = false; } ?> if("<?php echo $existance ?>") { window.open("done.php","_self"); } else { } }, 5000); } </script> </body> </html> As you can see, I use the "clearstatcache();" statement in order to make sure that the server's information is current before checking the existence of the file. I have also used meta tags, in the HTML, and php headers in order to make sure that nothing is being cached. This is all in an attempt to make sure that it's not looking at old data when it checks to see if the file exists. Despite all of this, the browser keeps reloading, over and over again, usually about ten times, even after the file exists. Any ideas why this is happening? Edited by Maq, 10 July 2014 - 03:52 PM. Similar TutorialsHi I'm currently writing a script that basically downloads videos from a specific page. I am downloading with cURL however with some files, they're so large cURL is timing out. This is causing either a) PHP to timeout b) PHP memory to run out c) cURL to stop once defined timeout limit is reached This means that some files are only partitially downloaded as some files are over 100mb and some are only 20mb I have Code: [Select] set_time_limit(0);and Code: [Select] ini_set("memory_limit","500M");set but is there a way to make it so PHP will not timeout and the cURL session will not timeout until the file is downloaded? how can i check if i have PHP SimpleXML on the opensuse is there a command that i can use in terminal Hello, I'm currently creating a little script, and want to assign a random number to a row in the MySQL table as soon as it will be inserted. But that number may not have been used before. How will I do this? I tried if else thingies, but then the code would be very long (just in case it randomly picks 10 times after each other a number that exists). $randomnumber = rand(10000000, 99999999); if(mysql_num_rows(mysql_query("SELECT * FROM table WHERE randomnumber='".$randomnumber."')) == 1) { $randomnumber = rand(10000000, 99999999); if(mysql_num_rows(mysql_query("SELECT * FROM table WHERE randomnumber='".$randomnumber."')) == 1) { $randomnumber = rand(10000000, 99999999); }else { // Insert into database } }else { // Insert into database } I hope you understand my problem. Regards, I have 2 tables, access_level and pages. In pages table i will have all the details of page like page_id, code, herf, pagename.. and i will select few from this table and store it in access_level table depending on the department and position. Now while editing, i will display all the pages which is stored in access_level pages with a particular page code along with those pages from pages table. if the page_id exists in access_level table, its has to get updated, if its not present then it should get inserted into access_level table. These things am doing with checkbox and <li>. my access_level table access_level.JPG 18.19KB 0 downloads and my pages table pages.JPG 37.86KB 0 downloads here is my code $s1 = mysql_query("SELECT pages.page_id as pid, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.department, access_level.position, access_level.active FROM pages LEFT JOIN access_level ON (pages.page_id=access_level.page_id AND access_level.department=".$department." AND access_level.position=".$position.") WHERE pages.code='snor die(mysql_error()); while($s2 = mysql_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['pid']; ?>" <?php if($s2['pgid'] === $s2['pid']) echo 'checked="checked"';?> /> <input type="hidden" value="<?php echo $s2['pid']; ?>" name="page_id[<?php echo $s2['pgid']; ?>]">while submittings i am not getting the logic, how can be done. Please somebody suggest me Okay, I have a script that is supposed to break if one of the errors occurs. However, it's not. I don't know if I have it coded incorrectly or what. Any help would be appreciated! Purpose of Script: The user is supposed to be able to spend "stat bonus points" to level up their stats. However, if they have 0 points, then obviously they can't spend them. If the user tries to use more points than they have, it's supposed to break too. Thanks in advance!! if (isset($_POST["statbonus"])) { include("tmpconfig.php"); $checkquery = $db->execute("SELECT * FROM `users` WHERE `id`=?", $player->id); //$rec = mysql_fetch_array($checkquery); extract($_POST); $errors = 0; $errorlist = ""; $rec = mysql_fetch_array($checkquery); extract($_POST); $errors = 0; $errorlist = ""; if (!is_numeric($stat_bonus)) { $errors++; $errorlist .= "The amount of bonus sent needs to be a whole number.<br />"; } if ($stat_bonus == "") { $errors++; $errorlist .= "The amount of bonus is required.<br />"; } if ($amount > $stat_bonus) { $errors++; $errorlist .= "You're trying to spend more stat bonus than what you have.<br />"; } if ($stat_bonus == "0") { $errors++; $errorlist .= "You need to spend more stat bonus than just zero.<br />"; } if ($errors == 0) { $query = $db->execute("UPDATE `users` SET `stat_bonus`=? WHERE `id`=?", array($player->stat_bonus - $amount, $player->id)) or die("querya failed: ". mysql_error()); if($query) $qry = $db->execute("select * from `users` where `id`=?", array($player->id)) or die("qry failed: ".mysql_error()); $rw = $qry->fetchrow(); if($qry){ $query2 = $db->execute("UPDATE `users` SET `stat_bonus`=?, $choice=$choice+$amount WHERE `id`=?", array($player->stat_bonus - $amount, $player->id)) or die("query2 failed: ". mysql_error()); if($qry){ echo("<br><br>You have successfully used your stat bonus points.<br>"); } else { echo "<font color=green><b>You have succesfully spent skill points!</b></font><br /><br />"; }}}} This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=347646.0 Here's what i got, a part of poll script, actually this is for a user with some more priviliges... The problem I am facing is actually that my php code doesn't even recognize the text in HTML Form - the text boxes(at least thats what I think so). I made 2 errors - one if client didnt type the title of poll and one if there are lower than 2 answers. And the problem is Im getting those 2 problems all the time no mather what I type in textboxes Code: [Select] <?php } function GetNewPollDetails(){ ?> <h1>Nova anketa</h1> <form name="frmAddPoll" action="managepoll.php?method=AddFinal" method="post"> <br /> Pitanje Ankete:<input type="text" name="$question" /> <br /> Odogovor 1:<input type="text" name="answer1" /> <br /> Odogovor 2:<input type="text" name="answer2" /> <br /> Odogovor 3:<input type="text" name="answer3" /> <br /> Odogovor 4:<input type="text" name="answer4" /> <br /> Odogovor 5:<input type="text" name="answer5" /> <br /> <input type="submit" value="Napravi" name="napravi" /> </form> <?php } function AddPoll(){ global $question; global $answer1; global $answer2; global $answer3; global $answer4; global $answer5; $numAnswers = 0; $err = ""; if($answer1 != "") { $numAnswers++; } if($answer2 != "") { $numAnswers++; } if($answer3 != "") { $numAnswers++; } if($answer4 != "") { $numAnswers++; } if($answer5 != "") { $numAnswers++; } if($question == "") $err .= "<li>You didn't enter a title</li>"; if($numAnswers < 2) $err .= "<li>You must enter at least two answer choices</li>"; if($err != "") { ?> <h1>Incomplete Fields</h1> You didn't complete all of the details for this poll. Take a look at the errors below and click the link below to go back and correct them: <ul> <?php echo $err; ?> </ul> <a href="javascript:history.go(-1)">Go Back</a> <?php return; } include("dbvars.php"); @$svrConn = mysql_connect($host, $user, $pw) or die("Couldn't connect to the database server"); @$dbConn = mysql_select_db("websitenforum", $svrConn) or die("Couldn't connect to the database"); $strQuery = "INSERT INTO pollQuestions VALUES("; $strQuery .= "0, '$question', '$answer1', '$answer2', '$answer3', '$answer4', '$answer5')"; if(mysql_query($strQuery)) { echo "You made it, yes!"; } } ?> Hi Members,
I am search for the reason for the problem why my mysql query cannot fetch data and store in file based on id in $variable form. For example, $sql="SELECT * FROM mytable WHERE mine_id='1234'"; works for me. But when i use $sql="SELECT * FROM mytable WHERE mine_id='$id'";, files are created as empty. I chanaged the quotes and could not store the data in file. So anyone please help me.
For more clear, i attach the part of my code
for ($i=0;$i<=10;$i++) { $id=$seqs[$i]; $dbo = new PDO($dbc, $user, $pass); echo $sql = "SELECT * FROM mine_id WHERE locus_id='$id'"; $qry = $dbo->prepare($sql); $qry->execute(); $data = fopen('file.csv', 'w'); while ($row = $qry->fetch(PDO::FETCH_ASSOC)) { fputcsv($data, $row); } } Edited by phpnewbie007, 20 November 2014 - 02:17 AM. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=333966.0 Hi All, I am trying to call a javascript pop-up window via a link by echoing out the html via php but keep getting parse errors: Parse error: syntax error, unexpected ')', expecting ',' or ';' Here is the code in question: Code: [Select] echo "<td class=\"today\"> <a href=\"javascript:statusWindow('status.php?month=".$month."&day=".$day."&year=$year');\">"$day_num</a> </td>\n"; And here is the javascript function: Code: [Select] <script type="text/javascript"> function statusWindow(url){ status_popupWin = window.open(url, 'status', 'resizable=yes, scrollbars=yes, toolbar=no,width=400,height=400'); status_popupWin.opener = self; } </script> Any help is appreciated. Thanks, kaiman Hey Folks This is a major long shot but is their a way that i can use php to upload one mp3 file and one doc file, then get the php script to place the mp3 file in one folder but also copy the mp3 file and make it into a zip file and place it into another folder as well as also make another copy of the mp3 file pair it with the doc file and make it into another zip file in yet another folder mp3->---------------------------->--mp3----------------->----mp3 into zip-------->--mp3 + doc into zip &---- > --Uploaded via php----->--placed in folder a--->----placed in folder b--->--placed in folder c doc-->---------------------------->--copied--------------->----mp3 copied--------->-- But thier is a catch the host i am using didn't activate ZipArchive() function so need a diferent way to make the zip file. Any Ideas people? because i have been pulling my hair out at this one please help Phil I would like to apply some addition functionality to a form which add news records into the database. Basicaly what i want is similar to what this forum does with the [ code ] [ /code ] but what i want for the user to be able to add [ quote ] [ /quote ] and when the post is viewed then that specific area of the acticle body will be formated diffrently. I hope this makes sence. Hi I'm trying to figure out how to calculate how long since a datevariable I have stored is from whenever the page is loaded.. I currently have a stored datevariable in the format: YYYY-MM-DD H:m:s ... So basically what I wish to accomplish is figuring out whenever i load the page which has stored this variable, how much time has passed. I want it to show up as for example : '10 minutes ago'.. '1 hour 25minutes ago' if it's the same day.. if its more than 1 day old it's enough to show only the number of days.....'1week 3 days ago' etc etc I try to get how long my message was sent with this... $Now = strtotime ("now"); $dateEnvoi = $fetchDiscussion['dateEnvoi']; //my date from my DB $timeEnvoi = mktime($dateEnvoi); $TempsEnvoi = $dateNow - $dateEnvoi; and it try to get how long it was post ... same thing as on facebook... like the 26 minutes ago from FB how can i do it ? If I break up this long line of code will it still work correctly? Original... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Desired... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Or maybe... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Debbie is it possible to get an ajax call to execute a php script that will continue running even if the user leaves my site? i have used cron jobs and tokens to do in past but this can result in 1 min delay. I'm working on a site that provides database results. To get to the final report, I'm going through a few pages where the user selects specific options. This builds up arrays that need to be passed from one page to another. As a result the final page has a pretty lengthy variable list. Since I want to provide a link to certain customers where they don't have to go through all the option select stuff, I'm using the GET method on the final page. Due to all the arrays I need to pass, I'm hitting hyperlink address character limitations, and I fear I will eventually hit browser URL length limits. Is there any way to provide links to customers without using the GET method so I could keep the URL length down? |