[PHP] multilanguage site: performance question: included file with cases?
Hello listmembers, I'm building up a site which should be german and english. So I have a site object which remembers this choice during the session and do a include('lang_'.$site->lang.'.php'); in my topmost.php. This works good, but this file is growing and I thought about how to handle this. Two things came in mind: 1. Split the content parts and use a different include file for each section. 2. Do a switch ($site->curMenu) in the lang_xx.php and define only what is needed for current section. The first option is not so good, as I would have up to 10 new files. And when thinking of the second option, I thought that it could be even more performant, if you had a static included file, as this could be cached somehow. So, what to do? And: hello to all, it's my first post here. :) -- shinE! http://www.thequod.de ICQ#152282665 I'm sitting in silence. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] multilanguage site: performance question: included file with cases?
on Wed, 17 Sep 2003 21:08:31 + Curt Zirzow wrote: >> I'm building up a site which should be german and english. So I have a >> site object which remembers this choice during the session and do a >>include('lang_'.$site->lang.'.php'); >> in my topmost.php. CZ> I would suggest using gettext it will make the application real CZ> flexible. I havn't used it but from what I've seen it really is CZ> simple to use. Plus it keeps your translations completely seperate CZ> from your program. CZ> http://php.net/manual/en/ref.gettext.php Thanks for your suggestion. I looked around, but did not get it working properly at first, because of strange behaviour of setlocale and no documentation (just many different comments on php.net) what is used to initialize gettext. after some hours I'm down to this code: putenv('LANGUAGE='.$site->lang); bindtextdomain ("tqV2", "./locale"); textdomain ("tqV2"); and it works.. :) But the same performance question resists: should I put all strings in one .po file or seperate them? Regarding collecting of already entered strings: there exists a tool called xgettext, which can parse the .php files and creates a .po file with all strings, but I'm unable to find a port for win32.. :/ -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc Apollo Four Forty - Alcatraz Within The Joint Remix vs. @440 rocks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] gettext: changed .mo file, caching issue
Hello php-general, I init gettext with putenv('LANGUAGE='.$language); putenv('LANG='.$language); // Specify location of translation tables bindtextdomain ("messages", "./locale"); // Choose domain textdomain ("messages"); where $language is either "de" or "en". This works good, but if the .mo file gets changed the old content is returned by calls to gettext, until I restart Apache. This is with my local server. On the remote server, where I upload the files there is even no translation ATM, although there already has been some. my local server is: Apache 1.3.27 PHP 4.3.3 LoadModule php4_module c:/www/php/sapi/php4apache.dll remote server is also Apache/1.3.27 (Linux/SuSE) PHP/4.3.3 mod_perl/1.27 Any solutions? -- shinE! http://www.thequod.de ICQ#152282665 Dj Sosse - Summerscream II rocks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] gettext: changed .mo file, caching issue
on Mon, 29 Sep 2003 10:24:09 +0200 Christophe Chisogne wrote: >> This works good, but if the .mo file gets changed the old content is >> returned by calls to gettext, until I restart Apache. CC> gettext uses a caching method to speed up looking translation CC> strings, which explain why Apache must be reloaded [1] That's bad, as I cannot restart Apache at my remote hosts computer.. I also found a blog entry, saying that "Because when PHP is running as an Apache module, each page gets handled by a separated thread of the same process. And the problem is, you set the language by writing a variable to the environment (puttenv()). That's how gettext works. Unfortunately, changing the environment affects the whole process... thus all running (sleeping indeed ) threads for that process!" see http://fplanque.net/Blog/devblog/2003/08/20/p355 That would mean that two different people accessing the page at the same time could get mixed up translations, as through PutEnv usage? CC> Perhaps you can try php-i18n mailing list, which is really low CC> traffic. Thanks for the hint. Just went through the archive, but did not find a good solution. Also discovered this list in the past days through google. So, I think I'll go back to simple include(). Still I have to think about using a single big one for each language or seperate it for sections with more content.. :/ -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc I'm sitting in silence or radio music. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ob_get_length() returns uncompressed buffer length (after ob_start('ob_gzhandler'))
Hello PHP, I found this small demonstration code on the net, that shows it really good. Call it with: wget --header="Accept-Encoding: gzip" --header="Connection: close" -S http://localhost/test.php on php-bugs I found that this is defined as "bogus", as the compression takes place after all output is collected. But I did not find an answer, how to correct this.. - using ob_implicit_flush(); did also not help. -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
note: [PHP] ob_get_length() returns uncompressed buffer length (after ob_start('ob_gzhandler'))
Hallo daniel, am Mon, 20 Oct 2003 13:45:18 +0200 schrieb ich bereits: dh> But I did not find an answer, how to correct this.. - using dh> ob_implicit_flush(); did also not help. is there no way to put header('Content-Length: '.$sth) in when you use ob_gzhandler in output buffering? that would be bad.. because you then would have to decide between bandwidth saving (ob_gzhandler) or fast transmitting (Content-Length), as there could be more threats cathcing up a particular file altogether. -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: note: [PHP] ob_get_length() returns uncompressed buffer length (after ob_start('ob_gzhandler'))
Hallo PHP-general list, on Wed, 22 Oct 2003 23:07:06 +0200 I already wrote: dh> Hallo daniel, don't want to talk only to myself.. this is for everyone.. :) -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] replace %rand[x]-[y]% macro in string with random string
Hello PHP-list, I'm building a script, that provides a honeypot of invalid email addresses for spambots.. for this I want to provide a macro for the templates that looks like %rand[x]-[y]%, where [x] and [y] are integers, that specify the length of the random script. My first thoughts were about the best parsing of the %rand..%-part, but now I came to a point, where I could also need suggestions on the random string generation.. It considers very basic word generations and the only meaningful word I discovered was 'Java'.. *g For generation of a random string with length 1.000.000 it takes about 13 seconds on my xp 1600+.. that's quite a lot, imho, so suggestions are very welcome.. the script goes here, ready to copy'n'paste: -- list($low, $high) = explode(" ", microtime()); $this->timerstart = $high + $low; function parserandstr($toparse){ $debug = 0; $new = ''; $ch = array( 'punct' => array('.', '.', '.', '..', '!', '!!', '?!'), 'sep' => array(', ', ' - '), 'vocal' => array('a', 'e', 'i', 'o', 'u'), 'cons_low' => array('x', 'y', 'z'), 'cons_norm' => array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w') ); while ( ($pos = strpos($toparse, '%rand')) !== FALSE){ if ($debug) echo '$pos: ' . $pos; $new .= substr($toparse, 0, $pos); if ($debug) echo '$new: "' . $new . '"'; $toparse = substr($toparse, $pos + 5); if ($debug) echo '$toparse: "' . $toparse . '"'; $posclose = strpos($toparse, '%', 1); if ($debug) echo '$posclose: "' . $posclose . '"'; if ($posclose){ $rlength = substr($toparse, 0, $posclose); if ($debug) echo '$rlength: "' . $rlength . '"'; $possep = strpos($rlength, '-'); $minrlen = substr($rlength, 0, $possep); $maxrlen = substr($rlength, $possep + 1); if ($debug) echo '$minrlen: "' . $minrlen . '"'; if ($debug) echo '$maxrlen: "' . $maxrlen . '"'; $rlen = rand($minrlen, $maxrlen); // generate random string $randstr = ''; $inword = 0; $insentence = 0; $lastchar = ''; for($j = 0; $j < $rlen; $j++){ if ($inword > 3 && rand(0, 5) == 1) { // punctuation chars if (rand(0,5) > 0) $char = ' '; else { $char = $ch['punct'][rand(0, count($ch['punct'])-1)] . ' '; $j += strlen($char)-1; $insentence = 0; } $inword = 0; } else { if (!$lastwasvocal && rand(0, 10) > 6) { // vocals $char = $ch['vocal'][rand(0, count($ch['vocal'])-1)]; $lastwasvocal = true; } else { do { if (rand(0, 30) > 0) // normal priority consonants $char = $ch['cons_norm'][rand(0, count($ch['cons_norm'])-1)]; else $char = $ch['cons_low'][rand(0, count($ch['cons_low'])-1)]; } while ($char == $lastchar); $lastwasvocal = false; } $inword++; $insentence++; } if ($insentence == 1 || ($inword == 1 && rand(0, 30) < 10)) $randstr .= strtoupper($char); else $randstr .= $char; $lastchar = $char; } $new .= $randstr; if ($debug) echo '$new: ' . $new; $toparse = substr($toparse, $posclose + 1); if ($debug) echo '$toparse: "' . $toparse . '"'; } else $new .= '%rand'; } return $new . $toparse; } function pre_dump($var, $desc=''){ echo '::'.$desc.'::'; var_dump($var); echo ''; } #$s = parserandstr('random string comes here: ' . '%rand10-1000%. this is a fake %rand and should not be killed..'); $s = parserandstr('%rand20-20%'); echo '' . $s; echo '' . strlen($s); list($low, $high) = explode(" ", microtime()); $t= $high + $low; printf("loaded in: %.4fs", $t - $this->timerstart); -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replace %rand[x]-[y]% macro in string with random string
on Tue, 2 Dec 2003 23:33:47 + Richard Davey wrote: RD> Just so we're clear on this - you're creating a string (an email RD> address) of a million characters? I don't know my mail RFC's that well, but RD> I'm sure this is well beyond what it considers "standard". We're not clear.. ;) the function I've posted is designed for templates, that handle the output my script generates.. it's useful to have non-email text portions in between or a short random string for the mailto-links description.. RD> Does the string HAVE to make sense? I found it better to follow some rules.. At first that were spaces in between and it got bigger.. if I'd write a spambot I would check if the page I'm lurking on is a oneliner or does only contain non-email words with > 20 characters, and so on.. -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: replace %rand[x]-[y]% macro in string with random string
on Wed, 3 Dec 2003 10:54:10 +1100 Luke wrote: L> result on my laptop for default script settings L> (P4 2.66, 512mb ram) L> 20 L> loaded in: 1.3158s thanks for the test.. L> please tell me what you think of this? if you like it i can email it to you L> (as a php file) Looks good, I have already something similar as "generate invalid addresses" in my project, which only needs translation of the config section and some logging statistics, which are done in MySQL. At first, I only wanted to do a floodprotection for the notifybyemail feature, but now I'm with the whole config part into db.. :o) Anyone who'd like to betatest this, is very welcomed to drop me an email. A release post will also go here.. -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replace %rand[x]-[y]% macro in string with random string
on 02 Dec 2003 18:56:28 -0500 Robert Cummings wrote: RC> I missed the original post, and I'm too lazy to go looking, but the RC> following code runs in approx. 2.75 seconds on my Athlon 2400 running RC> linux: it is 4.3 seconds on xp 1600+.. RC> $chars = '0123456789' RC> .'abcdefghijklmnopqrstuvwxyz' RC> .'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; RC> $charArray = array(); RC> for( $i = 0; $i < 100; $i++ ) RC> { RC> $charArray[] = $chars[rand( 0, 61 )]; RC> } RC> It's runs much faster than using a .= style of string creation. ..and replacing "$charArray[] =" with "$s .=" crawls this down to 3.5 seconds - so this is faster here.. winxp, php 4.3.4, Apache 1.xx -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replace %rand[x]-[y]% macro in string with random string
on Tue, 2 Dec 2003 23:46:33 +0100 I already wrote, regarding replacing macro %rand[x]-[y] with random of random length ([x]-[y]). Before, I had my own (slow!) procedure to find next occurence of the macro and generated a new string, which was returned. This took about 15 seconds for 10.000 addresses, where the macro could appear. As this was too slow, I rewrote it to use preg_replace (what a cool thing, to use a function as replacement) and this takes it down to about 2,5 seconds!! Very great - just want to lez you know that.. ;) So this is it: // replaces %rand[x]-[y]% with random text with length between [x] and [y] function parserandstr($toparse){ function genrandstr($minlen, $maxlen){ echo $minlen, $maxlen, ''; $ch = array( 'punct' => array('.', '.', '.', '..', '!', '!!', '?!'), 'sep' => array(', ', ' - '), 'vocal' => array('a', 'e', 'i', 'o', 'u'), 'cons_low' => array('x', 'y', 'z'), 'cons_norm' => array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w') ); $ch['newlineafter'] = array_merge(' ', $ch['punct'], $ch['sep']); $rlen = rand($minlen, $maxlen); // generate random string $randstr = ''; $inword = 0; $insentence = 0; $lastchar = ''; $lastwasvocal = false; $lastnewline = 0; $rbreak = rand(0, 100); for ($j = 0; $j < $rlen; $j++){ if ($inword > 3 && rand(0, 5) == 1) { // punctuation chars if (rand(0,5) > 0) $char = ' '; else { $char = $ch['punct'][rand(0, count($ch['punct'])-1)] . ' '; $j += strlen($char)-1; $insentence = 0; } $inword = 0; } else { if (!$lastwasvocal && rand(0, 10) > 6) { // vocals $char = $ch['vocal'][rand(0, count($ch['vocal'])-1)]; $lastwasvocal = true; } else { do { if (rand(0, 30) > 0) // normal priority consonants $char = $ch['cons_norm'][rand(0, count($ch['cons_norm'])-1)]; else $char = $ch['cons_low'][rand(0, count($ch['cons_low'])-1)]; } while ($char == $lastchar); $lastwasvocal = false; } $inword++; $insentence++; } if ($insentence == 1 || ($inword == 1 && rand(0, 30) < 10)) $randstr .= strtoupper($char); else $randstr .= $char; $lastchar = $char; if ($lastnewline > $rbreak && rand(0, 30) > 10 && in_array($char, $ch['newlineafter'])){ $randstr .= "\n"; $lastnewline = 0; $rbreak = rand(0, 100); } else $lastnewline++; } return $randstr; } $pattern = array('/%rand(\d+)-(\d+)%/e', '/%rand%/e'); $replace = array('genrandstr($1, $2)', 'genrandstr(5, 40)'); return preg_replace($pattern, $replace, $toparse); } -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] spambothoney: script to pollute spammer's databases
Hello PHP-list, I proudly announce the first release of my first PHP script: spambothoney. It provides a class to generate different types of email addresses (random invalid, combination of users/hosts, with spambots IP/host, "binary" output) and is meant to pollute the crawling spambots that harvest email addresses from webpages. It uses a MySQL database for configuration (through web-interface) and for logging purposes. I would be glad, if this is of some interest for you and you would take a look: http://thequod.de/comp/mysoft/spambothoney (direct download: http://thequod.de/action.php?download=1) I'm especially interested into security issues, but feedback in general is very appreciated.. Thanks.. have a nice week! -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Leechers...
on Tue, 9 Dec 2003 12:49:56 + [EMAIL PROTECTED] wrote: TPrsc> I want to now be able to stop people from linking to the images directly, TPrsc> and only be able to access the images via my site... With Apache you can either use mod_rewrite: RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://domain.com.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.domain.com.*$ [NC] RewriteRule .*(gif|png|jpe?g)$- [F] or more general method (don't know which mod this is): #prevent refering to my images SetEnvIfNoCase Referer "^http://www.domain.com/"; locally_linked=1 SetEnvIfNoCase Referer "^http://domain.com/"; locally_linked=1 SetEnvIf Referer "^$" locally_linked=1 Order Allow,Deny Allow from env=locally_linked both can be added to your .htaccess file. -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP IDE?
on Sat, 13 Dec 2003 09:06:56 -0800 (PST) Jough Jeaux wrote: JJ> Was wondering what everyone's favortie IDE is for JJ> coding in PHP. I've got a big PHP project in the JJ> works. I'll be doing alot with it and am looking for JJ> ways to boost my productivity. Used to use UltraEdit some time, but now I'm with jEdit. It's an OpenSource Java editor and supports plugins.. so you can manage Projects and a lot more. It's main target (from the number of plugins) is Java development, but it's great for PHP/HTML also. http://www.jedit.org/ -- shinE! http://www.thequod.de ICQ#152282665 PGP 8.0 key: http://thequod.de/danielhahler.asc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] build list of available functions and classes
Hello, for the purpose of automatically building a syntax highlighting file for jEdit I wanted to write a script that does this automatically by retrieving http://php.net/quickref.php and extracting it. Unfortunately the syntax for the function names there is not trivial. For example, the swfbitmap::getheight() is named (content of the tag) swfbitmap.getheight in the list. This is great and could be easily detected (because of the point). But AFAICS the SWF classes are the only ones that use this naming convention. So I've taken the output from PHP 5.0.3's get_declared_classes() and test if the part of the function name before the first '_' is one of those classes and handle it as a class function then (cut the class name in front). Another problem are the old DOM-XML class functions that are prefixed with 'dom_', which I optionally match in the regexp. Wouldn't it be easier to use the syntax "class.function_name" for the names? I've attached the script, so you can probably better understand what I mean.. ;) -- happy new year!http://thequod.de/contact) * @version 2004-12-30 */ error_reporting(E_ALL); $urls = array( 'quickref' => 'http://www.php.net/quickref.php', 'aliases' => 'http://zend.com/phpfunc/all_aliases.php', ); /** * @var array holds all functions */ $functions = array(); /** * @var array holds all functions for classes (classnames are keys) */ $functionsForClasses = array( // {{{ 'arrayiterator' => array(), 'arrayobject' => array(), 'cachingiterator' => array(), 'cachingrecursiveiterator' => array(), 'com' => array(), 'compersisthelper' => array(), 'com_exception' => array(), 'com_safearray_proxy' => array(), 'directory' => array(), 'directoryiterator' => array(), 'domattr' => array(), 'domcdatasection' => array(), 'domcharacterdata' => array(), 'domcomment' => array(), 'domconfiguration' => array(), 'domdocument' => array(), 'domdocumentfragment' => array(), 'domdocumenttype' => array(), 'domdomerror' => array(), 'domelement' => array(), 'domentity' => array(), 'domentityreference' => array(), 'domerrorhandler' => array(), 'domexception' => array(), 'domimplementation' => array(), 'domimplementationlist' => array(), 'domimplementationsource' => array(), 'domlocator' => array(), 'domnamednodemap' => array(), 'domnamelist' => array(), 'domnamespacenode' => array(), 'domnode' => array(), 'domnodelist' => array(), 'domnotation' => array(), 'domprocessinginstruction' => array(), 'domstringextend' => array(), 'domstringlist' => array(), 'domtext' => array(), 'domtypeinfo' => array(), 'domuserdatahandler' => array(), 'domxpath' => array(), 'dotnet' => array(), 'exception' => array(), 'filteriterator' => array(), 'limititerator' => array(), 'parentiterator' => array(), 'php_user_filter' => array(), 'recursivedirectoryiterator' => array(), 'recursiveiteratoriterator' => array(), 'reflection' => array(), 'reflectionclass' => array(), 'reflectionexception' => array(), 'reflectionextension' => array(), 'reflectionfunction' => array(), 'reflectionmethod' => array(), 'reflectionobject' => array(), 'reflectionparameter' => array(), 'reflectionproperty' => array(), 'simplexmlelement' => array(), 'simplexmliterator' => array(), 'sqlitedatabase' => array(), 'sqliteexception' => array(), 'sqliteresult' => array(), 'sqliteunbuffered' => array(), 'variant' => array(), // autodetect-classes ("class.function" syntax) without methods (to get removed) 'swfaction' => array(), /** * @obsolete PHP4 */ 'domattribute' => array(), 'domxsltstylesheet' => array(), ); // }}} // Get PHP's quickref-list and extract it {{{ $buffer = file_get_contents( $urls['quickref'] ); preg_match_all( '#]*>' .']*>(\w+)' // alias .']+>[^<]+' // source .'\w+#', // orig $buffer, $matches, PREG_PATTERN_ORDER ); $aliases = isset( $matches[1] ) ? array_unique($matches[1]) : array(); natsort( $aliases ); // }}} /** * Internal function to echo a keyword */ function echo_keyword(
[PHP] PHP Unit Tests - which framework to use?
Hello PHP - General, I'm looking for a PHP Unit Test framework and found so far: SimpleTest: https://sourceforge.net/projects/simpletest/ PEAR PHPUnit: - http://pear.php.net/package/PHPUnit - http://pear.php.net/package/PHPUnit2 Sourceforge PHPUnit: http://phpunit.sourceforge.net/ While SF PHPUnit seems to have stalled (2002-10) there are still PEAR PHPUnit and Simpletest. I'd like to hear your opinions/experiences on what's better to use. I'm mainly searching it for an OSS project, but would like to use it at work, too. I'm still on PHP4 mainly - but tests could be done/run with PHP5 of course (if PHPUnit2 supports that). Thanks for any input. -- shinE! GnuPG/PGP key: http://thequod.de/danielhahler.asc ICQ#152282665 Random software tip: [***] The Bat! - Natural E-Mail System (http://www.ritlabs.com/the_bat/) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php