Jump to content

Dead6re

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Dead6re's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. This is most likely due to the encoding of the browser, you will need to tell PHP to send the header with character encoding UTF-8. header('Content-Type: text/html; charset=utf-8');
  2. Seems that PDO is supposed to act the way it is as the warning I have is a E_NOTICE error. Generally a PHP config is set with E_ALL & ~E_NOTICE for production environments and thus isn't seen. Changing the timeout seem to help reponsiveness in the script.
  3. Having trouble getting PDO exceptions to work, instead is raising the error handler in PHP. The connection string is fine, the port is supposed to be incorrect so I can generate a log message and show an simple error screen to the client. Warning: PDO::__construct() [pdo.--construct]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://127.0.0.1:3305) PHP Version 5.3.2 MySQL Version 5.1.47-community try { $options = array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); $this->db = new PDO($dsn, $username, $password, $options); //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //$this->db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } catch (PDOException $e) { $this->throwError('PDODatabase->connect', 'Connection Failed: ' . $e->getMessage()); return false; }
  4. Okay, I think I need to explain a bit more. I have a template class in PHP that should replace values within {} brackets. Inside those brackets, the characters A-z, 0-9, Hyphen (-), Pipe (|), Comma (,), Full-stop (.) & Forward Slash (/). Using the expression tester here using my expression it works: http://www.gskinner.com/RegExr/ However using it in PHP does not. For some reason matching {} brackets from my file does not work. It seems that having a range of A-z 0-9 matches more than one character However matching a special character seems to match it once and not more. e.g. It should match all expressions within the {} brackets below [in navy] (Simple HTML) <html> <head> <title>{title}</title> {css|style.css,layout.css} </head> <body> {hyperlink|ahref|text}{randomtext} </body> </html>
  5. Hello, I'm having a problem trying to match pipe characters if there is more than one: e.g. {hyperlink|ahref|text} Using: $this->contents = preg_replace_callback('/\{[A-z0-9\-\|,\.\/]+\}/', array($Template, 'replace'), $this->contents);
  6. Heres your problem and it has nothing to do with caching. Your saying your file is 700kb big? If so, optimize that!!! Obiviously files server side will be bigger as they get parsed and show only the input you want. Split the code into different files based on what they do so you don't use memory storing scripts you won't be using. Remove unneeded HTML code and start using CSS to dress up the HTML instead. The displayed filesize by the phpfreaks forum for this page is roughly 6kb. The SMF boards looks to only include less than 100-200kb of actual PHP files.
  7. Just a few things, I notice you use overflow:hidden to prevent the page width increasing if you have a long line of characters. Break this up! e.g. function SingleWordwrap($String, $Width){ $String = explode(' ', $String); $NewString = ''; foreach ($String as $Value) { $Len = strlen($Value); if($Len > $Width) $Value = wordwrap($Value, $Width, '–<br/>', true); $NewString .= $Value.' '; } return $NewString; } $Comment = SingleWordwrap($Comment, 20); You strip the tags for posts, what happens if you have a technical post and people want to respond with code? Instead of stripping the comments you can use htmlentities: $Value = htmlentities($Value, ENT_QUOTES, 'UTF-8', false); Then use the MySQL escapestring function. Finally, if you post an incorrect form, you lose all the stuff you had previously written. Use $_POST to retrieve what you had before and also display the error message.
  8. Your problem occurs in Line: 61 Char: 6 Error: 'document.getElementByID(...)' is null or not an object function handleHttpResponse() { //if the process is completed, decide to do with the returned data if (http.readyState == 4) { sResults = innerHTML = http.responseText.split(","); //results is now whatever the feedback from the asp page was //whatever the variable glo_show's (usermsg for example) innerHTML holds, is now whatever was returned by the asp page. document.getElementById(gShow).innerHTML = ""; document.getElementById(gShow).innerHTML= sResults } } Updated: Thats the code causing a problem so far.
  9. By passing a string through MD5 twice you increase the chances of collisions, it is better to use a salt that will prevent rainbow tables from being used.
  10. Unclear error message too, since it seems to be wrong. [attachment deleted by admin]
  11. Hey, It isn't causing a infinite loop so I don't have to worry about a 'stack overflow'. The problem seems to be with file_get_contents, using the latest version so it seems like it may be a PHP bug. I just wanted to make sure. See my replication steps which are clearly not a infinite loop.
  12. Trying to build a basic template system that can include files recursively and it keeps crashing... class lib_Template { var $Contents; var $Assign; function lib_Template($File = './Templates/default.tpl') { if (@file_exists($File)) { $this->Contents = @file_get_contents($File, 'FILE_TEXT') or $this->ThrowError("Unable to load template file ($File) contents."); } else { $this->ThrowError("Template file ($File) does not exist."); } $this->Assign = array(); } function Add_Tag($TagName, $String) { $this->Assign[$TagName] = $String; } function Add_Tags($Tags) { foreach ($Tags as $TagName => $String) { $this->Assign[$TagName] = $String; } } function LoadFile($File) { $Buffer = file_get_contents('./Templates/'.$File); if (count($this->Assign) > 0) { foreach ($this->Assign as $Tag => $Data) { $Data = (file_exists('./Templates/'.$Data)) ? $this->LoadFile($Data) : $Data; $Buffer = str_replace('{'.$Tag.'}', $Data, $Buffer); } } } function ReplaceTags() { if (count($this->Assign) > 0) { foreach ($this->Assign as $Tag => $Data) { $Data = (file_exists('./Templates/'.$Data)) ? $this->LoadFile($Data) : $Data; $this->Contents = str_replace('{'.$Tag.'}', $Data, $this->Contents); } } } function Display() { $this->ReplaceTags(); echo $this->Contents; } function ThrowError($ErrorMsg) { $s_Error = 'lib_Template: '.$ErrorMsg; throw new Exception($s_Error); } }; Basically, if you create three template files such as default.tpl, menu.tpl message.tpl with the contents default.tpl -> {menu} menu.tpl -> {message} message.tpl -> {username} Init the template class: $g_Template = new lib_Template(); $g_Files = array('menu' => 'menu.tpl', 'message' => 'message.tpl', 'username' => 'Dead6re'); $g_Template->Add_Tags($g_Files); $g_Template->Display();
  13. My orignal code = 5-10 seconds. My new code: This page was created in 0.311986923218 seconds YES!!! How I did it? Performing the 60 odd queries I was doing was slow. It was basically, lets loop through every system id until we have finished. Now, since we know I only need a list of systems and a count of the planets and moons, couldn't I just group the results and count those? From 60 queries down to 3, lets cheer! Yes. <?php //error_reporting(E_ALL); set_time_limit(0); // Processing time $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $MySQL = mysql_connect('localhost', 'root', '') or die('Could not connect to MySQL Database'); // Connect or die. // RegionID - Catch = 10000014 $qCatch = mysql_db_query('eve', "SELECT solarSystemID, solarSystemName FROM mapsolarsystems WHERE regionID = '10000014' ORDER BY solarSystemName ASC LIMIT 0, 50"); $Catch = array(); $qPlanets = mysql_db_query('eve', "SELECT solarSystemID, COUNT(groupID) FROM mapdenormalize WHERE regionID = '10000014' AND groupID = 7 GROUP BY solarSystemID"); while ($row = mysql_fetch_array($qPlanets)) { $Catch[$row['solarSystemID']]['planets'] = $row['COUNT(groupID)']; } mysql_free_result($qPlanets); $qMoons = mysql_db_query('eve', "SELECT solarSystemID, COUNT(groupID) FROM mapdenormalize WHERE regionID = '10000014' AND groupID = 8 GROUP BY solarSystemID"); while ($row = mysql_fetch_array($qMoons)) { $Catch[$row['solarSystemID']]['moons'] = $row['COUNT(groupID)']; } mysql_free_result($qMoons); while ($row = mysql_fetch_assoc($qCatch)) { $ID = $row['solarSystemID']; $Planets = $Catch[$ID]['planets']; $Moons = $Catch[$ID]['moons']; $Catch[$ID]['name'] = $row['solarSystemName']; echo "$ID - $Name ($Planets - $Moons)<br>"; } /* foreach ($Catch as $ID => $Name) { echo "$ID - $Name<br>"; } */ // End MySQL connection. mysql_close($MySQL); // Processing Time $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "<br>This page was created in ".$totaltime." seconds";
  14. For some reason, my code is running really slowly whilst using the SELECT COUNT statements. It takes 10 seconds to run and return just 30 results. I tried using SELECT *something* then SELECT FOUND_ROWS() but that also takes a long time. I know I'm performing 60 odd queries, but surely it should be quick or can be optimized. I'm counting rows, not parsing data! <?php //error_reporting(E_ALL); set_time_limit(0); // Processing time $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $MySQL = mysql_connect('localhost', 'root', '') or die('Could not connect to MySQL Database'); // Connect or die. // RegionID - Catch = 10000014 $qCatch = mysql_db_query('eve', "SELECT solarSystemID, solarSystemName FROM mapsolarsystems WHERE regionID = '10000014' ORDER BY solarSystemName ASC LIMIT 0, 30"); $Catch = array(); while ($row = mysql_fetch_assoc($qCatch)) { $ID = $row['solarSystemID']; $Catch[$ID]['name'] = $row['solarSystemName']; $qPlanet = mysql_db_query('eve', "SELECT COUNT(solarSystemID) FROM mapdenormalize WHERE solarSystemID = $ID AND groupID = 7"); $Planet = mysql_fetch_array($qPlanet); $Planet = $Planet[0]; mysql_free_result($qPlanet); $qMoon = mysql_db_query('eve', "SELECT COUNT(itemID) FROM mapdenormalize WHERE solarSystemID = $ID AND groupID = 8 LIMIT 1"); $Moon = mysql_fetch_array($qMoon); $Moon = $Moon[0]; mysql_free_result($qMoon); } foreach ($Catch as $ID => $Name) { echo "$ID - $Name ($Planet - $Moon)<br>"; } // End MySQL connection. mysql_close($MySQL); // Processing Time $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "<br>This page was created in ".$totaltime." seconds";
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.