Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. You cannot remove a cookie per se, but you can overwrite it with a new cookie that has the same name and an expiration date in the past.
  2. Of course I could, but I'll leave it to you as an exercise. It's quite simple logic. I'm sure you can work it out if you try, and you'll benefit more by doing it yourself than having people feed you the answers
  3. Figure out how many pages there are. If the current page number equals the last page number, then the "Next" link shouldn't be shown. The first page is 1, so if that is the current page number the "Previous" link shouldn't be shown.
  4. The file passwd.inc.php is being included. Try taking a look at that file. Sounds like it could be that one.
  5. If the cPanel password and the MySQL database password are the same, that is likely the case. Why don't you try updating the password in your config file and see if that works?
  6. You forgot to close the if (or the foreach depending on how you look at it).
  7. Any reason why you don't store them as separate fields?
  8. C:\Users\daniel>ab -c 10 -n 1000 http://localhost/smarty_test/mysqltable_smarty.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.11 Server Hostname: localhost Server Port: 80 Document Path: /smarty_test/mysqltable_smarty.php Document Length: 9574 bytes Concurrency Level: 10 Time taken for tests: 7.575 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 9740000 bytes HTML transferred: 9574000 bytes Requests per second: 132.01 [#/sec] (mean) Time per request: 75.754 [ms] (mean) Time per request: 7.575 [ms] (mean, across all concurrent requests) Transfer rate: 1255.60 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 2.1 0 15 Processing: 17 74 26.4 71 209 Waiting: 15 73 26.5 69 207 Total: 19 75 26.3 72 209 Percentage of the requests served within a certain time (ms) 50% 72 66% 83 75% 90 80% 96 90% 112 95% 124 98% 139 99% 154 100% 209 (longest request) More or less the same.
  9. Well, ord() only works for ASCII characters. Hiragana characters are in the range 3040 to 309F and the katakana characters are in 30A0 to 30FF. The kanji are in 4E00 to 9FBF. So to check if a string solely consists of kana or kanji you'll have to check that each character in the string lies within these ranges in Unicode. There are a few functions in the comments on ord that allegedly works with Unicode.
  10. Given that smarty is compiled into PHP, the performance increase is probably just because your old code sucked. No offense. I'm entirely unimpressed by template engines. Taken straight from "Why Use Smarty?" is this example: <table> {section name=art loop=$article} <tr> <td>{$article[art].headline}<td> <td>{$article[art].date}<td> <td>{$article[art].author}<td> </tr> {/section} </table> Can you tell me how this gives me any benefit over this? <table> <?php foreach ($articles as $article): ?> <tr> <td><?php echo $article['headline'] ?><td> <td><?php echo $article['date'] ?><td> <td><?php echo $article['author'] ?><td> </tr> <?php enforeach ?> </table> Here is a quick little benchmark I decided to make. Each time we'll use ab with 1000 requests and a concurrency of 10. This is on Windows 7, PHP 5.3, Apache 2.2.11 and MySQL 5.1.36. No PHP accelerator/opcode cache is installed. First I'm going to test just the loading of Smarty. static_smarty.php: <?php require './lib/Smarty.class.php'; echo 'Hello World'; static_plain: <?php echo 'Hello World'; Testing the Smarty version we'll get: C:\Users\daniel>ab -c 10 -n 1000 http://localhost/smarty_test/static_smarty.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.11 Server Hostname: localhost Server Port: 80 Document Path: /smarty_test/static_smarty.php Document Length: 11 bytes Concurrency Level: 10 Time taken for tests: 2.574 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 197000 bytes HTML transferred: 11000 bytes Requests per second: 388.48 [#/sec] (mean) Time per request: 25.741 [ms] (mean) Time per request: 2.574 [ms] (mean, across all concurrent requests) Transfer rate: 74.74 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.6 0 6 Processing: 5 25 3.0 25 42 Waiting: 3 25 3.0 25 42 Total: 5 25 3.0 25 42 Percentage of the requests served within a certain time (ms) 50% 25 66% 26 75% 27 80% 27 90% 29 95% 30 98% 32 99% 35 100% 42 (longest request) And next the plain version: C:\Users\daniel>ab -c 10 -n 1000 http://localhost/smarty_test/static_plain.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.11 Server Hostname: localhost Server Port: 80 Document Path: /smarty_test/static_plain.php Document Length: 11 bytes Concurrency Level: 10 Time taken for tests: 0.656 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 197000 bytes HTML transferred: 11000 bytes Requests per second: 1524.30 [#/sec] (mean) Time per request: 6.560 [ms] (mean) Time per request: 0.656 [ms] (mean, across all concurrent requests) Transfer rate: 293.25 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.5 0 3 Processing: 2 6 1.3 6 13 Waiting: 2 6 1.3 6 12 Total: 2 6 1.3 6 13 Percentage of the requests served within a certain time (ms) 50% 6 66% 7 75% 7 80% 7 90% 8 95% 9 98% 10 99% 10 100% 13 (longest request) Now we'll try doing something that is actually useful. For this purpose I've imported the PHP Freaks tutorials into my local database and the scripts will be listing the tutorials. This time we'll have an init file that opens a connection to the database and fetches the info (just so I didn't have to type it twice). mysqltable_init.php: <?php $db = new PDO('mysql:host=localhost;dbname=test', 'root', '******'); $stmt = $db->query('SELECT content_id, title, permalink, summary, created_at FROM content ORDER BY created_at DESC'); mysqltable_smarty.php: <?php require './lib/Smarty.class.php'; require './mysqltable_init.php'; $smarty = new Smarty(); $smarty->assign('tutorials', $stmt->fetchAll()); $smarty->display('mysqltable.tpl'); mysqltable.tpl (Smarty template): <h1>PHP Freaks Tutorials</h1> {section name=tut loop=$tutorials} <div class="tutorial" id="tut-{$tutorials[tut].content_id}"> <h2>{$tutorials[tut].title|escape}</h2> <small>{$tutorials[tut].created_at|date_format:"%B %e, %Y, %H:%M"}</small> <div class="summary"> {$tutorials[tut].summary|escape} </div> <a href="http://www.phpfreaks.com/tutorial/{$tutorials[tut].permalink}">Read more</a> </div> {/section} mysqltable_plain.php: <?php require './mysqltable_init.php'; echo '<h1>PHP Freaks Tutorials</h1>'; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo '<div class="tutorial" id="tut-' . $row['content_id'] . '">' . '<h2>' . htmlentities($row['title']) . '</h2>' . '<small>' . date('F j, Y, H:i', strtotime($row['created_at'])) . '</small>' . '<div class="summary">' . htmlentities($row['summary']) . '</div>' . '<a href="' . htmlentities($row['permalink']) . '">Read more</a>' . '</div>'; } First we benchmark the Smarty version: C:\Users\daniel>ab -c 10 -n 1000 http://localhost/smarty_test/mysqltable_smarty.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.11 Server Hostname: localhost Server Port: 80 Document Path: /smarty_test/mysqltable_smarty.php Document Length: 9574 bytes Concurrency Level: 10 Time taken for tests: 7.677 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 9740000 bytes HTML transferred: 9574000 bytes Requests per second: 130.25 [#/sec] (mean) Time per request: 76.774 [ms] (mean) Time per request: 7.677 [ms] (mean, across all concurrent requests) Transfer rate: 1238.92 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 2.4 0 27 Processing: 13 75 30.1 72 265 Waiting: 13 73 29.9 69 265 Total: 14 76 30.0 73 265 Percentage of the requests served within a certain time (ms) 50% 73 66% 84 75% 93 80% 98 90% 117 95% 132 98% 146 99% 159 100% 265 (longest request) And the plain PHP version: C:\Users\daniel>ab -c 10 -n 1000 http://localhost/smarty_test/mysqltable_plain.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache/2.2.11 Server Hostname: localhost Server Port: 80 Document Path: /smarty_test/mysqltable_plain.php Document Length: 8232 bytes Concurrency Level: 10 Time taken for tests: 2.984 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 8398000 bytes HTML transferred: 8232000 bytes Requests per second: 335.10 [#/sec] (mean) Time per request: 29.842 [ms] (mean) Time per request: 2.984 [ms] (mean, across all concurrent requests) Transfer rate: 2748.22 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.4 0 3 Processing: 6 29 10.3 29 83 Waiting: 5 29 10.3 28 82 Total: 7 30 10.3 29 83 Percentage of the requests served within a certain time (ms) 50% 29 66% 33 75% 36 80% 38 90% 43 95% 48 98% 54 99% 57 100% 83 (longest request) Results: Test name: Static [/td] Requests per second Total time (seconds) Plain PHP 1524.3 0.656 Smarty 388.48 2.574 Here it takes a lot more time just loading Smarty. Test name: MySQL table [td]Requests per second Total time (seconds) Plain PHP 335.10 2.984 Smarty 130.25 7.677 Here our plain PHP version that actually does something is only a little slower than the Smarty version that doesn't do anything. Smarty is of course slower than PHP here as well.
  11. Except Japanese characters aren't part of ASCII...
  12. SELECT COUNT(*) AS Num FROM jobs WHERE DATE >= NOW() - INTERVAL 26 HOUR;
  13. You already have one topic about this.
  14. Right, that means that $row doesn't contain any value. You will need to replace $row with an array that contains the user info.
  15. http://www.phpfreaks.com/forums/index.php/topic,256583.msg1207033.html#msg1207033
  16. Try to place var_dump($row['level']); right before the if. What does that output?
  17. You should use a tinyint and store 0 or 1 instead. When cast as boolean, these will represent false and true, respectively.
  18. You can use DOM or SimpleXML to parse it.
  19. Ha... good catch. Fixed now.
  20. Daniel0

    Hexspeak

    57,005. A real challenge now? Sure, here you go: http://www.claymath.org/millennium/
  21. Hmm... I didn't know we had a WYSIWYG editor.
  22. Daniel0

    Hexspeak

    If only DEAD people know hex, how many people know hex?
  23. That is an erroneous operation. You are not allowed to manipulate or otherwise use uninitialized variables. It'll result in an E_NOTICE type error.
  24. function pmsgInsert($this->parentconvo, $title, $bd, $to, $from) { Red part isn't allowed. You cannot do that.
×
×
  • 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.