26

(5 replies, posted in Programming)

I don't know about php's preg's... my experience with php preg functions has been @#$!%@@ #$%!!#@%$^%# #@$ $#@$@# @$$# #@$&^^$#$

I'd try something like this:

preg_replace_all('/([^\\])\%/', '\2five', 'What is %?');

Also what smarty said is probably right. At one point perl was alot faster the sed at processing strings, since perl was designed (originally) for just that. php is still relatively young, and I think the preg functions were just thrown in by some guy who never used perl in the first place. sprintf is probably much more efficient. Heck even the php docs tell you to avoid the preg function set... And why in the world are the 10 "perl compitible" functions for 2 different perl syntactical statements? I want to kill the fool who decided preg's don't need the /regex/[modifyers]...

str_replace('%', 'five', 'what is %?');
str_replace('\\five', '%', 'what is five?');

Should do the trick in half the time.

Looks like your not the only one. Maybe the suggestion in the reply will help? http://forums.mysql.com/read.php?34,42051,42051

You could use the BigDump script but alter it, to write a copy of the db-backup to a new file. At least then you'll know if it's the parsing of the backup, or the adding to the db, and where in the backup the problem lies. Might just be a version conflict between the old and new box?

Your biggest problem is using a dedicated BSOD "server", ever tongue You have older back-ups of the db, or a db from the same/similar set-up that can be restored to your new set-up? You might also try to run a windows web/mysql server on your local computer, do the restore and then do the conversion. Then back-up that conversion and try to restore it. Somewhere on these forums is a link to an apache, mysql, php and a few others all-in-one installer (for windows and *nix, even mac if I remember correctly).

I was browsing the web to find out the efficiency of OOP vs Procedural in PHP and came across this test. It seemed to be missing some extra tests, soes here's my results (P4 2.8G Hyper-Threading, 2x512 Duel Channel RAM, PHP v5.1.6).

test.php:

<?php

define('REPEAT',        10000000);
define('REPEAT_DIV_10',    1000000);

class test
{
    function one()
    {
        return 1;
    }
}

function one()
{
    return 1;
}

$results[] = time()."\n";

for ($i=0; $i<REPEAT; $i++)
{
    $testclass=new test();
    $cnt+=$testclass->one();
}

$results[] = time()."\n";

$testclass=new test();
for ($i=0; $i<REPEAT; $i++)
{
    $cnt+=$testclass->one();
}

$results[] = time()."\n";

for ($i=0; $i<REPEAT; $i++)
{
    $cnt+=one();
}

$results[] = time()."\n";

for ($i=0; $i<REPEAT; $i++)
{
    $cnt+=1;
}

$results[] = time()."\n";

for ($i=0; $i<REPEAT_DIV_10; $i++)
{
    $testclass=new test();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
}

$results[] = time()."\n";

$testclass=new test();
for ($i=0; $i<REPEAT_DIV_10; $i++)
{
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
    $cnt+=$testclass->one();
}

$results[] = time()."\n";

for ($i=0; $i<REPEAT_DIV_10; $i++)
{
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
    $cnt+=one();
}

$results[] = time()."\n";

for ($i=0; $i<REPEAT_DIV_10; $i++)
{
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
    $cnt+=1;
}

$results[] = time()."\n";

for ($i=0;$i+1<sizeof($results);$i++)
{
    echo "Results ($i):\t".($results[$i+1] - $results[$i])."\n";
}
 $ php ./temp.php 
Results (0):    18
Results (1):    9
Results (2):    8
Results (3):    4
Results (4):    7
Results (5):    6
Results (6):    5
Results (7):    1
 $ php ./temp.php 
Results (0):    18
Results (1):    9
Results (2):    9
Results (3):    4
Results (4):    7
Results (5):    6
Results (6):    5
Results (7):    1
 $ php ./temp.php 
Results (0):    17
Results (1):    9
Results (2):    8
Results (3):    4
Results (4):    7
Results (5):    6
Results (6):    5
Results (7):    0
 $ php ./temp.php 
Results (0):    17
Results (1):    9
Results (2):    8
Results (3):    4
Results (4):    7
Results (5):    6
Results (6):    5
Results (7):    1
 $ php ./temp.php 
Results (0):    17
Results (1):    9
Results (2):    8
Results (3):    4
Results (4):    7
Results (5):    6
Results (6):    5
Results (7):    1

Result 0 is creating an object each time the function is called. Rightly so, it's terribly slow.

Result 1 is creating an object once, and then calling a function each loop. It's usually about 1 second slower then Result 2. I'm guessing that's the overhead on calling an object's function (not 1 second, but probably around 1 / RESULT seconds per call). This is not the overhead of creating an object the first time since the object was created the first time in Result 0 (also, just to make sure this "first time" creation didn't affect Result 0, I commented out everything but the Result 0 code, then 1, etc... and got the same times).

Result 2 is calling a function each loop. a touch faster then using the object, but does not seem significant.

Result 3 is not making any calls. About 2x faster then using functions, but also much harder to read/maintain (in medium/large projects).

Result 4 is creating an object every 10 function calls. It calls the function the exact same amount of times as Result 0 (or 1 or 2 or 5 or 6 for that matter tongue), but creates the object 10 times less often. Comparing these results to 0 through 3 it would seem that the for loop has it's own overhead. It would also seem that object creation has significant overhead when done often.

Result 5 is creating an object once, and calling the function the same amount as results 1 (or 0 or 2 or 4 or 6 for that matter tongue). Again we see about 1 second overhead when calling an objects function.

Result 6, same amount of function calls, just done with less loops.

Result 7... OMG... if only we didn't need to call functions, eh? from 5 seconds to 0! Course you'd have to leave out loops too (Result 3, doing the addition once per loop was 4 seconds). Be interesting to see a php "compiler" that just parsed out function calls and loops at the cost of file size.

Conclusions: It's not that costly to use a few "Global objects" that are only created once each page hit, and are used in a few places in that pages code. Any objects that need to be re-created often will probably start showing their cost, and could be optimized by using procedural function calls instead (or using a single object to do the job of the multi-creation object class). If your worried about the 1 second overhead (or less/more? php's time() probably isn't the best score card tongue), then you should also be worried about the overhead of loops and function calls. Result 3 vs Result 7 was only 10 times less loops, but was 4 times faster in the second set. Note to self: Write a script to parse out functions, classes, and loops, then spit out unintelligible non-OOP, non-procedural php, from an intelligible php source smile

Hope this helps yous in some way, I learnt something... I think... 0.o

Well... you posted the php code to display a java object. I don't really know anything about how this java applet stores user information without seeing it's code.

Ok, how do I do that? The good thing is the chat room opens in a new window in my forum, so that would be perfect.

I sort of tried to say before... Don't do this in php, or javascript. Use the code that the chatroom is already using. FYI disabling javascript and disabling java are two different things. People could have java applets allowed without allowing javascript.

You might be able to find some php code on the google.country that will let you query an IRC server for it's current user list. That would also work here. All you need is the IRC's user list, in a php variable. No need to create another full blow online list for one php page.

EDIT --

Doing this from the php page also means that users who figure out your IRC channels location, and use something like mirc to connect instead of the page won't be listed.

PunBB: --> Insert description here <--

the variable in_chat_room in the online table to 1 when somebody goes to that page and to 0 when he leaves it.

When someone enters is easy. When someone leaves... if they close the browser? if they type a new address in the address bar? if they have javascript disabled (javascript ~could~ catch the last two examples)? Also what about guests, who decide to log-on. One guest out, one new user, ect... ect...

Does the chatroom have a user list that shows up when using the irc chatroom thingy? You could steal that code and put it in your miniportal.

34

(1 replies, posted in Programming)

Attachment mod will do this afaik. check it out on http://www.punres.org/

    if ($num_users > 0)
        echo "\t\t\t".'<dl id="onlinelist" class= "clearb">'."\n\t\t\t\t".'<dt><strong>'.$lang_index['Online'].': </strong></dt>'."\t\t\t\t".implode(',</dd> ', $users).'</dd>'."\n\t\t\t".'</dl>'."\n";
    else
        echo "\t\t\t".'<div class="clearer"></div>'."\n";

to

    if ($num_users > 0)
    {
        echo "\t\t\t".'<dl id="onlinelist" class= "clearb">'."\n\t\t\t\t".'<dt><strong>'.$lang_index['Online'].': </strong></dt>'."\t\t\t\t"
        foreach ($users as $user)
        {
            echo '<dd><img src="img/mycutomavartars/'.$user.'" />'.$user.'</dd>';
        }
        echo "\n\t\t\t".'</dl>'."\n";
    }
    else
        echo "\t\t\t".'<div class="clearer"></div>'."\n";

Assuming:

The thumbnail profile picture link will be based on the username

If that's not the case you'll have to query the db for each users avatar number.

Probably add this in the bbcode parser? instead of just the img link
<div class="scrollable_small_image"><img src="blah" /></div>

Probably add this in the base.css

/* Make a 150x150 pixel image (or smaller) display normally
* Make a 151x150 pixel image (or larger) display with scrollbars.
*/
div.scrollable_small_image
{
  overflow:           auto;/*or "scroll" auto only shows scrollbar when content to small, scroll aways shows*/
  display:             inline;
  max-width:       150px;
  max-height:      150px;
}

You might want to remove the display: inline; or fart around to find a way to add a margin to the div. Any div that's displayed as inline has a tendancy to ignore margin and padding sizes.

37

(4 replies, posted in PunBB 1.2 show off)

Download binary version of say xorg and kde, then start it up and start working. Build xorg and kde from source in the background.

Personally I prefer using a Knoppix DVD for a working desktop during install, but to each their own?

38

(6 replies, posted in PunBB 1.2 troubleshooting)

It Just Wants To Download the php file.

If your host does support php, did you allow executable permission on the php files? 0755 should do (-rwxr-xr-x)

39

(2 replies, posted in PunBB 1.2 discussion)

Search around in punres. I've seen a few smilies mods, never used any though.

It can be updated with cron or manually from the administration control panel, i think the last one is beter.

I'd go with an sql query. Limit the number of matches returned to speed the process up. Since your only sorting topic "subjects" this will not be as major a query as you might think.

Now i would like it to look like a forum post and to be acessible from a sticky link in the viewforum.

Why not just put a link near the "post new" link. Have it link to 'search.php?fid=<forum_id>&action="sortalpha"', then do all the work in the search.php file. This way you also have some control over the number of times a single user can make this query (there's an admin option to limit the secnds between searches).

td's can only have a padding in IE, and tables only a margin... If I remeber correctly anyways... that might be the IE problem? Also IE's width parameter includes the padding, but excludes the border and margin (if it's DT Strict).

Looks nice so far smile

Dono if this will work for you... but... I do it on my box, to have 1 single raid array for multiple directories, and 1 "base system" root partition with just a etc, bin, and sbin  (incase the raid fails; or the "base" fails, since the base is actually mirrored to a different disk).

fstabs

# Assuming you have /dev/hda2 as root, and /dev/hda3 as the "www jail" partition, alter this to suite your system :)
/dev/hda1       /boot                           reiserfs        defaults,noauto                                 0 2
/dev/hda2       /                               reiserfs        defaults                                0 1
/dev/hda3       /mnt/chroot/www_jail            reiserfs        defaults                                0 2
/dev/hda4       none                            swap            sw,pri=1                                        0 0

# Ok, now the fun stuff
/mnt/chroot/www_jail/var/www         /var/www            none            bind                                            0 0
/var/run/mysql                 /var/www/run/mysql            none            bind                                            0 0

Basically the bind option will mount a directory to another directory. It's not exactly a directory hardlink, but in (most ^.~) practises it is. Personally I like the /dev/hd3 -> /mnt/chroot/www_jail mount, because you could create a series of directories, or files on that partition, and then bind them all around. I use this technic on my raid array, so that 99% of the system is running off the raid array, but that 1% is running off a tiny (like 1G is overkill) partition. When the raid array fails, in a bad way, that "backup" root partition can take over until I can fix the problem. Also, being 1G, I have it minored incase the root partition fails and not the raid array smile (sides, I'm using kernel sw raid, and it doesn't like being told to be a root partition).

Anywho, the mount -bind option is what you want, and that fstabs example shows the fstab syntax smile

43

(13 replies, posted in Programming)

MadHatter wrote:

in my opinion, procedural programming concepts just don't provide the necessary functionality to produce reusable, extensible and data protected applications.

I agree that conceptually OOP is better. In practice, OOP is better. I disagree that data, configuration, functionality, etc... couldn't be "private" in procedural programing though.

lets say for a second that punbb was an oo implementation.  ...snip

having an object to inherit, or having a series of functions that an extention has to call/have are the same thing. The object can require functions explicitly, the object can call functions implicitly. That's what OOP does. It adds a series of syntactical phrases that when parsed, explain to the compiler what the requirements to make use of a "block" of functions is, and what the requirements to extend a block of functions is. Procedural programming leaves all the infering to the coder, giving them more power and less parenting. But, if you are really freaky... Like I said before, find 1 thing you can do in OOP, that you couldn't do in procedural tongue

config.php...

function getDbName() { return "value"; }

// or... I dono...

function GetPunConfig($key)
{
  function __LoadVariables()
  {
     // Well... get the pun_config array from where ever... and return it :P
  }
  static $pun_config = __LoadVariables();

  switch ($key)
  {
    case 'joe_obsolete_variable':
      return 0;
      break;

    default:
      return $pun_config[$key];
      break;
  }
}

getDbName() { return GetVariable('db_name'); }

Now assign random values to $pun_config till you go blue in the fingers, and unless you've managed to get your cursor to the GetPunConfig function that config data is safer then a ~private~ member variable in an object! Ohhh, ohhh and try to call __LoadVariables();, I dare yah smile

44

(15 replies, posted in PunBB 1.2 troubleshooting)

Dam deceptively names truncate variable smile Try this?

###############
# Near top
###############
function pun_news($fid='', $show=15, $truncate=250)

###############
# Near Middle
###############
        // Display first paragraph only (comment out next four lines to turn off)
        if ($truncate)
        {
            $paragraph = '';
            for ($numchar=0; $numchar<$truncate; $numchar++)
            {
                if (isset($cur_post['message'][$numchar]))
                    $paragraph .= $cur_post['message'][$numchar];
                else break;
            }
            $paragraph .= ' …';
            $cur_post['message'] = $paragraph;
        }

###############
# Bottom top
###############
echo pun_news(2, 5, 250);

There you go, now it truncates at the char. (Please not that if it truncates away the end tag of a BBcode statement, you might get into trouble tongue)

45

(13 replies, posted in Programming)

OOP is a syntax, not a way to control variable scope. Anything done in C++ can be done in C, using static variables, or "local" globals, or externs, etc... ie:

include.h ---

extern int x, y;

include.c ---

int x, y, z;

// do stuff to x, y, and/or z

main.h ---

#include include.h

// do stuff to only x or y... you know nothing about z at all... almost like z was a member variable of object include.h? wow...

int z = 5;

// Now in main.c z=5... it doesn't affect the variable z referenced in include.c

good structured programing would be to never declare variables as externs, and force any user of the include.h function set to pass pointers to an internal structure... wait? isn't this what an object is? a structure? with a series of functions, that when called automatically pass the pointer to the structure as the first/last param (depending on compiler, language, etc...). OOP is syntax, not functionality. You can have inherence without OOP, you can correct a single line in a function and fix a bug in 900 other functions that make use of it. Saying OOP is anything other then a style and a little extra overhead during compile time (but not always during runtime) is like saying a Toyota car can turn corners, so you shouldn't turn a corner in a Ford car, cause only Toyota's can turn corners... tongue You may turn the corner differently in a Ford, but simply because a Toyota can do it, doesn't mean a Ford can no longer tongue It's a style, and a person may be more adept at one or the other, but either one can and will get you from A to B just as fast, and efficiently (Ok... Ford was a bad example... A ford will get you from A to B with a $2,000 repair bill tongue But you get the idea smile ).

./template/main.tpl?

That rw should be <pun_title> I ~believe~ (someone please correct me, since i'm wrong, before nick reads this smile)

47

(13 replies, posted in Programming)

OOP adds reliability to a program and it's more accurate

OOP is to programing what color is to tv.
color doesn't do anything for the message of a tv show. It makes it look all ... colorful ... though tongue
OOP doesn't improve a programmers code ... it makes it ... OOPful ... though tongue

By the way, why doesn't PunBB use PDO?

It does if you need sqlite3 support like I did, follow the link in the sig smile

Secondly, what about the file permissions? is that file set to be readable by all? some servers might even require you to set it to executable by all too tongue

49

(15 replies, posted in PunBB 1.2 troubleshooting)

dude, your a canadian... you should know this stuff tongue
is this the mod with a "front page" and the 3 param function call? you try setting truncate to 250? XD
Also... ummm, look at the mod's code... somewhere in that function that you call, it should find the topic_id. from that you can create a "comments" link.
I'm guessing you want something like the frontpage on my site? with the comments link and the number of comments?

Some image hosts will do this for you, http://www.imageshack.us/ comes to mind.

You could alter the bbcode parser to include a link to the image and have the img tag have a style="max-width: 100px; max-height=100px;". This will meen if the image is 200MB, every client will download that 200MB images, but at least it will only display in a 100x100 image box (in most browsers the aspect ratio will remain unchanged too).