PHP - Time For Server To Build Page Check
Is there a way to run a check on the server to see how long it takes for the page to get built, then print it to the screen?
I tried searching for it online for a few minutes, but it wasn't able to be found. All I'm finding on there is how to optimize the pages, but I want a simple time check performed on the page loading
Similar TutorialsHello Coders, Iam in a confused situation. I made a php script & in that script i want to check how much time (in seconds) the page is taking to fetch the content from the server. If the time is greater than to i defined time then i want to show a error message to the users. Anybody can give me ideas ..................... ?? Instead of breaking down and actually learning how to use ajax, I'm thinking about trying to do something so I don't need a page refresh every time, and the filtered data is nearly instant. I just use the session array var, and build a new array from the rows that meet the conditions. I'm thinking of loading a two dimensional array into a session var, then use some input buttons, and use the post vars to filter the array based on a set of predefined conditions. ie status = 0, status = 1. It's a fairly small number of conditions applied to two different fields. So, I need to access specific fields within a row, and essentially create a new array either including or excluding that row depending on whether it met the condition. I'm struggling on several parts. 1. not sure how to build the array so that I can access specific fields, then not sure how to access those fields. Do I do this..... to build the array? .... Code: [Select] while($row = mysql_fetch_assoc($result)){ $array[] = array($row['field1'], $row['field2']); } I was thinking about using a foreach and is_array() to get to each row... Code: [Select] foreach($array as $key => $value){ if(is_array){ foreach($value as $k => $v){ if($v[0] == 1){ //stuck here $v[0] is not a field, it's the first char of the string. not sure how to access a field $new_array[] = $value; //stuck here. I need to put the whole row back into the array if the condition was true. seems like I would have to use the field selectors and rebuild the array. } } } } What would you do? Open to any ideas. PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. Hi, The hosting provider for my domain confirm me that the server time is in EST (UTC-5). They also sent me a grab supporting that Code: [Select] server time is now: ---------------------- Sun Nov 7 02:20:01 EST 2010 ------------------- But when I use the following code, the output I get is has 1 hr difference (UTC-6) echo date("d M, Y h:i:s A",time()); Output==> 07 Nov, 2010 01:20:01 AM But it suppose to give the same time as the server, ryt? Can anybody please explain? Thanks, I have a web portal which is scripted using client side scripting language i.e HTML. I want to create a login page in .php and want the other pages to be in .hmtl. Can i do so? I want to do this because i want the login password to be stored in a database. Also I want the password to get encrypted (by either MD5 javascript or OpenSSL ) when user enters it inside the login form. I cannot create the entire portal in php because my portal makes use of C code. And php doesn't have an interface with C language. Can a user get directed to a .html page after a secure login from login.php page ? My main aim is to secure the access to my web portal using a password. I tried to authenticate the login using javascript where the password was stored in an array. But i feel any one having moderate knowledge can easily break that password. Any help would be greatly appreciated!! I got this code off of this forum Code: [Select] <?php $ip="{$_GET['ip']}"; $port="{$_GET['port']}"; header('Content-type: image/png'); if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) { readfile('image/offline.png'); } else { readfile('image/online.png'); } ?>I'm able to check the status by going to Code: [Select] http://domain.com/statuscheck.php?ip=google.com&port=80 and it works fine. But I would like to show the status on my index.html page without having to click on a link. Is there anyway Please help. thank you in Advance. I'm not sure if this is the place to ask this question, but please advise <?php echo "time=" . time(); ?> does the time change when viewing in other countries? E.g. Is echo the same when viewed in China, US, New Zealand? Thanks! Hi to all;
Is there any way, a function for example in php to add to my script in order to guess if the running script is facing a cpu overload or a memory overload or a slow processing speed ?
Thanks
Hello, I made a server statuc checking script that checks the status of a game server. It works fine on my computer, but when I upload it to my web host it stops working. I'm assuming my web host is blocking it in some way. My host is Yahoo Small Businesses. Does anyone know if they block this kind of thing, or if there is a way to unblock it? Perhaps editing the code? Here is my code, if that helps. Code: [Select] <?php function GetServerStatus($site, $port) { $status = array("OFFLINE", "ONLINE"); $fp = @fsockopen($site, $port, $errno, $errstr, 2); if(!$fp) { return $status[0]; } else { return $status[1]; } } $Redemption = GetServerStatus("174.142.118.233", 11661); $RedemptionPossible = GetServerStatus("174.142.118.234", 51665); $Tranquility = GetServerStatus("174.142.118.234", 11601); $TranquilityPossible = GetServerStatus("174.142.118.234", 51665); $Nemesis = GetServerStatus("174.142.118.241", 11601); $NemesisPossible = GetServerStatus("174.142.118.241", 64721); $OverallServer = GetServerStatus("174.142.118.237", 11093); $CodServer = GetServerStatus("8.9.6.122", 4230); echo($CodServer . "<br />"); echo("Overall Server: " . $OverallServer . "<br />"); echo("Redemption: " . $Redemption . "<br />"); echo("Tranquility: " . $Tranquility . "<br />"); echo("Nemesis: " . $Nemesis . "<br />"); ?> A beginner question.. I have tried "isset" but it aint working.. I wonder what PHP function to use to check if a user actually put a file to be uploaded on the server. A validation just in case a user just click the submit button w/out even choosing a file first. I have this code but it aint working... Code: [Select] <?php if(isset($_POST['submit'])) { if(isset($_FILES['uploaded_file'])) { echo "<span class=\"error_validation\">You haven't choose a logo to upload!<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } else { if($_FILES['uploaded_file']["type"] == "image/gif") { $target_path = "logo/"; $target_path = $target_path. basename('matzhee_logo.gif'); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) { echo "<span class=\"error_validation\">The Logo has been successfully changed! Refresh the page to see the changed!<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } else { echo "<span class=\"error_validation\">There was an error uploading the logo. Pls. try again.<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } } else { echo "<span class=\"error_validation\">Invalid file format. We are only accepting image file. Pls. try again.<br></span>"; echo "<span class=\"error_validation\">Upload Logo Again? <a href=\"edit_logo.php\">Click Here</a><br></span>"; } } } else { me_redirect_to("edit_logo.php"); } ?> Anyone? thanks im wondering is there any easy way to echo server time and local time... without converting them from unix to timestamp i have found thi code, but i cant tell is it server or local Code: [Select] echo date("H:i" ,time()); I just recalled using date(); time() for lots of things in my database, including post times etc. At first I simply assumed this used server time or something, but when I changed my PC's time, it changed ! Now, shortly after this I simply assumed this was because of me using a localhost? But I am not certain anymore.. If I would place this online, would date() and time() return you server time or user time? I couldnt find it on google =-( I've been looking for a simple script that would connect to a game server to see if it is still online. I've found many, but not one of them work. They will permanently send back the text "Online", or "Offline". This is the simplest code I have found: <?php $ip = "66.79.190.40"; $port = "27960"; if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) echo '<B><FONT COLOR=red>Offline</b></FONT>'; else{ echo '<B><FONT COLOR=lime>Online</b></FONT>'; fclose($sock); } ?> I'm also looking into getting it to pull the map name and player-list, but I should be able to figure that out on my own once I get this working. If it helps, this script is supposed to connect to the original Quake games(One, two, and three). I have written a small script for my own personal use that checks the servers of my favorite sites to see if they are operational. I'm having trouble getting it to work, I have most of it (I think) and I'm very new to PHP. The script also allows for a form to add any sites to the file, which I think I explode into an array correctly, at a later time. Here's my code, Please Help! <html> <head> <title>project.php</title> </head> <body> <?php $filename = "websites.txt"; $file = file_get_contents($filename); // reads entire file into a string $DomainNames = explode("\n", $file); // split the string at new line characters, returns an array $length = count($DomainNames) - 1; // count is the correct way to get the length of an array $i=0; while($i<=$length){ $fp = @fsockopen ($DomainNames[$i], 80, $errno, $errstr, 10); if (!$fp) echo "$DomainNames[$i] : <font color='red'>Failed!</font>"; else { echo "$DomainNames[$i] : <font color='green'>Online!</font>"; echo "<br>"; $i++; } } if (isset($_POST['submit'])) { $DomainNames[] = $_POST['url']; // append url to array $file = implode("\n", $DomainNames); // convert array to string, delimiting by new lines file_put_contents($filename, $file); // save contents to file } ?> <form action="project.php" method="post"> <fieldset> <label for="url">Url: </label> <input type="text" name="url" id="url" /> <input type="submit" name="submit" id="submit" value="Add URL" /> </fieldset> </form> </body> </html> I am using this php to write to a text file to show me who has logged in and when: Code: [Select] <?php $time = $_SERVER['REQUEST_TIME']; $myusername = $_POST['myusername']; $data = "$REQUEST_TIME\n"; $data = "$myusername\n"; //open the file and choose the mode $fh = fopen("logs/login.txt", "a") ; fwrite($fh, $data); fwrite($fh, $time); fclose($fh); ?> The result I get in my text file is: paul 1315919200melody 1315919221tracy&graham 1315919232ed&hannah 1315919251 I would feel more successful if the name of the user were to appear on the next line down but I can live with that but I can't make head nor tale of the date. I want it to say: paul 13:59 13/09/2011 next user 14:00 13/09/2011 and so on I feel I have done very well to even get that far really and wouldn't have been able to yesterday. I am frustrated to have reached the extent of my current understanding. If anyone can tell me where I'm going wrong, that would be great. I hope the php isn't too far off, and you can "read between the lines" as it were to see what I'm trying to do. Paul MOD EDIT: code tags added. I need to check (from a Debian server to a Mac CLIENT (not server) machine) to see if a file exists on the file system...not an http server. Here's what I've tried (based on reading at http://www.php.net/manual/en/function.ssh2-exec.php) Code: [Select] <?php function check_remote_files($username, $hostname, $remote_file) { $connection = ssh2_connect($hostname, 22, array('hostkey'=>'ssh-rsa')); if (ssh2_auth_pubkey_file($connection, $username, '/root/.ssh/id_rsa.pub', '/root/.ssh/id_rsa', '')) { echo "Public Key Authentication On Server #2 Successful\n"; } $url = "if ssh $hostname stat $remote_file \> /dev/null 2\>\&1"; $stream=ssh2_exec($connection,$url); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); $stream=ssh2_exec($connection,"then"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); $stream=ssh2_exec($connection,"echo File exists"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); $stream=ssh2_exec($connection,"else"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); $stream=ssh2_exec($connection,"echo Not found"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); $stream=ssh2_exec($connection,"fi"); stream_set_blocking( $stream, true ); $cmd=fread($stream,4096); fclose($stream); } ?> NOTHING happens after the echo of Public Key Authentication On Server #2 Successful. I'm running this script from a bash shell. Any ideas what might be wrong? Thanks. So I am trying to check if the current time is one hour before a variable time: Code: [Select] $date_game=$dt->format('Y n j'.$pieces[2]); echo $date_game; echo date('Y n j H'); if (date('Y n j H') < $date_game) { echo "The time is before the stored time"; } This displays 2012 1 21 17:30 2012 1 21 16 i.e $pieces[2] = 17:30. and $dt formatted Y n j = 2012 1 21. The current Y n j H is 2012 1 21 16. I want to know if it is more than one hour until the date/time stored in $date_game. At the moment it just tells me that it is before that time. Can I do something like Code: [Select] $data_game - 1->format('H'); or something? Thanks guys Could i use curl to check api response time and if so how? Hey All, I will be marketing a simple php script shortly and would like to Obfuscate my code and have it check to see if the person is running the script on the proper domain, much like other Purchased Scripts, you have to buy licenses and some are limited to a Per Domain basis. Could I use cURL to run a script on another server (mine) that takes the URL it came from, and a variable "the auth key" and check if the person is using the script on the proper domain? If the domain and auth key don't match in the DB i would return a message saying invalid key or something, else continue to execute the script. <?php //authkey would be defined in config file $authkey = "769870afhljkzxf90436"; $curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,"http://example.com/page.php?authkey=$authkey"); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)) { print "Sorry, AuthServ is performing maintenance.....<p>"; } else { print $buffer; } ?> Is there a smarter way to do this? I don't have an extra 300 bucks to use something like ioncube, just looking for a general proper direction on going about this as I am totally clueless. thanks Hi All - I'm trying to see if the below is possible using PHP. is it possible for php to allow a user to check if a port is open/listening on a remote server/PC, from their local machine. I've seen scripts on the web that talk about opening cmd.exe - this won't work as not all of my users will be on windows. Also saw fsock.. but the remote server is not serving http page(s). Also saw telnet, but again, some of my users may not have that windows feature enabled. Desired workflow: 1. user enters the server hostname/IP and a port 2. my php webapp will emulate checking if that hostname and port is open from the local user's computer.
thanks! |