|
drcru posted:They probably have terrible pings since you're likely somewhere in North America and they're XX hours away by plane. I'm in the UK and so is the web server the site runs on, but I guess the same applies. Thing is, the game isn't one for which a high ping should make a difference. It's a web version of a board game, and it's played in a turn-based fashion via the web site (nothing more advanced than dynamically generated html pages), so nothing is time-critical. If they have a poor connection then I guess the pages would take longer to load than is ideal, but the way I read his email it sounded like they are sometimes unable to access the website at all. I was wondering whether there are any particularly likely reasons for that. moops posted:Don't reinvent the wheel.. Use gettext *e.g. php:<? echo '<img src="gfx/trans1.png" border=\'0\' alt="The '.$spacenumbers[$i].'industry space in '. $spacetowns[$i].' is occupied by a'.$flipstatus.'flipped '. //** $whatplayer.' Tech Level '.$TechLevels[$i].' '. $whatindustry.'." style="position: absolute; top: '. $TileYPositions[$CompactBoard][$i].'px; left: '. $TileXPositions[$CompactBoard][$i].'px; z-index: 8"></a>'; ?>
|
# ? May 15, 2009 19:43 |
|
|
# ? Jun 3, 2024 22:33 |
|
Re: Hammerite Well, you've built your code in a way that makes transaltion very awkward. Ideally you would be using a system that builds strings with placemarkers for the values you need to insert. Like "you have :things: things remaining". Then run a function to insert your values in one go. You then need to know whether you need to translate before inserting them (in which case you need a method to exclude the placeholder tags from translation, e.g. not translating anything inbetween :: in my example string) or after. Importantly in this; for the love of god build a string for your alt text then use that string when you build your markup tags; as it stands you have to extract it from your mess of code, since you don't want to be translating the a tag itself. here's some psuedocode: non-translated but not a mess either: php:<? $image = 'gfx/trans1.png'; $params = array('things', 14); $string = 'you have :things: thingies left'; //ready to output: $alt = parameterise($string, $params); echo make_img_tag($image, $alt); ?> (you can also be assured EVERY img tag is built right if you use a single fuction for them all) massive change required for translation: php:<? $image = 'gfx/trans1.png'; $params = array('things', 14); $lang='de'; $string = 'you have :things: thingies left'; //ready to output: $alt = parameterise(translate($string, $lang), $params); echo make_img_tag($image, $alt); ?> But I suspect you have made your bed of monolithic code. You must sleep in it.
|
# ? May 15, 2009 21:33 |
|
KuruMonkey posted:But I suspect you have made your bed of monolithic code. You must sleep in it. I think you may be thinking my code is worse than it actually is. I chose one of the most complicated examples I could find to make my point. The section I c&p'ed is actually part of the contents of a loop (for $i from 0 to 42, do...)
|
# ? May 15, 2009 23:09 |
|
I have a 'dataprocessor' library written in PHP that parses through a CSV file that varies in size (1K to 2M). The larger files end up taking quite a bit of memory because of the looping required to manipulate the actual data itself. Now my question - is there a way to free up memory in PHP during the execution of the script? I call the unset() function on the variables that are unused but I don't think that unset is actually meant to free up memory.
|
# ? May 18, 2009 19:59 |
|
Tap posted:I have a 'dataprocessor' library written in PHP that parses through a CSV file that varies in size (1K to 2M). The larger files end up taking quite a bit of memory because of the looping required to manipulate the actual data itself.
|
# ? May 19, 2009 00:31 |
|
Tap posted:I have a 'dataprocessor' library written in PHP that parses through a CSV file that varies in size (1K to 2M). The larger files end up taking quite a bit of memory because of the looping required to manipulate the actual data itself. Hrmm.... I wouldn't know how to optimize your code unless I saw it, but PHP is not always memory efficient when you load up a file. It could very well be that a 2mb file takes up 40mb of memory when you load the whole file up. Its just the way PHP is. You should read up on how php manages memory and reference counting. Often unset won't do what you expect it to do, for instance in this case code:
From a coding and functional viewpoint though, you can work as though it was copied. If you then change the value of $x to something else, $y still will have a value of 'hi there' and $x will get assigned the new value. At that point the original memory location reference count is decremented by 1, and you now have two strings in memory, each with a ref count of 1. No calling unset($x) would actually free up space. Confusing hey? Well you could be running into issues such as this when trying to optimize your code.
|
# ? May 19, 2009 17:20 |
|
Begby posted:I thought $y =& $x does a reference, not $y = $x . Does it work differently in your example?
|
# ? May 20, 2009 03:08 |
|
Zorilla posted:I thought $y =& $x does a reference, not $y = $x . Does it work differently in your example? The following shows this behavior: php:<? define(BASE_MEMORY, memory_get_usage()); function print_memory_change($str = "") { $change = memory_get_usage() - BASE_MEMORY; echo "$str{$change}B\n"; } print_memory_change('Initial: '); $a = str_repeat(" ", 1048576); print_memory_change('After $a init: '); $b = $a; print_memory_change('After $b "copy": '); $b[0] = "_"; print_memory_change('After $b modify: '); unset($a); print_memory_change('After $a unset: '); unset($b); print_memory_change('After $b unset: '); ?> code:
Not until $b (or $a) is modified is the actual value copy needed, and only then does PHP actually make the copy in memory. supster fucked around with this message at 04:45 on May 20, 2009 |
# ? May 20, 2009 04:41 |
|
Did PHP garbage collect after the unset calls or does it just consider that memory free because it can be GCed whenever the hell GC runs?
|
# ? May 20, 2009 14:41 |
|
Munkeymon posted:Did PHP garbage collect after the unset calls or does it just consider that memory free because it can be GCed whenever the hell GC runs? No way to force it. It runs whenever, though I think you can encourage it to be more frequent with an ini setting, but I can't find it at the moment.
|
# ? May 20, 2009 16:35 |
|
That's not what I was asking. I'm asking whether PHP is reporting memory use after a hypotheical GC or whether the GC has already run and the memory is acually free to be used again.
|
# ? May 20, 2009 16:59 |
|
Anyone ever use dtrace with PHP? If it works well, I may just switch our servers over to Solaris.
|
# ? May 20, 2009 17:35 |
|
Munkeymon posted:That's not what I was asking. I'm asking whether PHP is reporting memory use after a hypotheical GC or whether the GC has already run and the memory is acually free to be used again. I am tempted to say that unset() is actually freeing up the memory. If anyone knows for sure I would really like to know.
|
# ? May 20, 2009 23:26 |
|
Getting this error:quote:Fatal error: require_once() [function.require]: Failed opening required 'PEAR.php' (include_path='.:/php/includes:/usr/share/php:/usr/share/pear') in /var/www/vhosts/foobar.org/httpdocs/Joomla159/administrator/components/com_civicrm/admin.civicrm.php on line 15 Except... PEAR.php exists in /usr/share/pear. Any ideas?
|
# ? May 21, 2009 01:28 |
|
Is this kind of memory usage too high? I have 1GB of RAM. final: 607.7265625kB peak: 860.96484375kB took 0.010162115097 seconds edit: I'm doing three sql queries and processing the table data of one of the result sets in this page. Acer Pilot fucked around with this message at 03:56 on May 21, 2009 |
# ? May 21, 2009 03:54 |
|
lol no
|
# ? May 21, 2009 04:03 |
|
supster posted:lol no Thank god. What would be too high for three sql queries? I haven't seen anything go over 1 megabyte.
|
# ? May 21, 2009 04:09 |
|
Don't worry about it unless it is the direct cause of a problem. Your question also can't be answered without more information. What is the data? What are you doing with the data? (Don't even bother answering these, it's not a problem.)
|
# ? May 21, 2009 04:26 |
|
Thanks, I've stopped worrying about it now. Here's another one, what do you guys use for templating your pages? Other than Smarty that is. Do you roll your own systems or just put the HTML in with your code? I've been using Smarty personally but it seems a little too much for what I need to do.
|
# ? May 22, 2009 19:37 |
|
drcru posted:Thanks, I've stopped worrying about it now. I don't use a templating system personally, but then it becomes my responsibility to make sure I keep anything but control logic out of my views. Here's a small example of what my views end up looking like. php:<?php foreach($mysqlResult as $res) : ?> <div><?php echo $res->title; ?></div> <div><?php echo $res->body; ?></div> <?php endforeach; ?>
|
# ? May 22, 2009 19:50 |
|
drcru posted:Thanks, I've stopped worrying about it now. I use the CodeIgniter framework (although I am starting to use Kohana). If smarty is too much, then these are probably way overkill for you, but wouldn't hurt to take a gander. Kohana: http://www.kohanaphp.com/ CodeIgniter: http://www.codeigniter.com
|
# ? May 22, 2009 19:58 |
|
Nevermind.
pooptart fucked around with this message at 15:06 on May 23, 2009 |
# ? May 23, 2009 14:39 |
|
supster posted:That's a good question. I don't know. Either unset is forcing garbage collection to free up that object iff its reference count is 0, or memory_get_usage() returns the hypothetical memory usage. Garbage collection occurs two places: 1) when a scope ends (e.g. a return from a function or method) 2) when you call unset. You can run a simple test to check that unset() actually causes the memory to be freed. For example, the following code is run and I watch the OSes reported memory usage (via top) - with the unset commented out, memory usage of the process grows and eventually it hits the memory limit. If I run it again with unset uncommented, it runs to completion without taking up any more memory than the "data" string needs while its still active: code:
http://us2.php.net/gc_enable
|
# ? May 23, 2009 19:19 |
|
I am making a wiki like site (I'm not using Mediawiki because I want something simpler) but I want to use/retain a lot of the similar formatting features as far as editing pages. What is the standard way this is done? Such as putting <p> tags around blocks of text and converting ==Hello World== into <h2>Hello World</h2> and so on. Is it just straight up string parsing with a lot of counting involved or is this a different way? Or would it be easier to simply allow certain html tags? EDIT: Would it be easier for me to just use something like php markdown ? http://michelf.com/projects/php-markdown/ Sylink fucked around with this message at 08:44 on May 24, 2009 |
# ? May 24, 2009 08:08 |
|
Sylink posted:I am making a wiki like site (I'm not using Mediawiki because I want something simpler) but I want to use/retain a lot of the similar formatting features as far as editing pages. There are much simpler wikis out there. Why re-invent the wheel? For the actual answer to your question, look at the source to Mediawiki and others and see how they do it.
|
# ? May 24, 2009 18:30 |
|
I want a different set of searchable attributes for pages and its easier to design it myself.
|
# ? May 24, 2009 22:52 |
|
Do any of these have anything in common? I saw someone making two way hashes like this and I'd like to try and do the same: 2ed3cbd5 11e1d49a 478c139d d72d0f17 They look like they're hexadecimal and from what I see it's supposed to be related to the number 1073. Is there something in mcrypt that encodes variables like this? edit: it looks like it has something to do with pack() and unpack() Acer Pilot fucked around with this message at 01:39 on May 25, 2009 |
# ? May 25, 2009 01:19 |
|
The "Try/Catch" feature of PHP isn't doing what I indend it to do..php:<? while (true) { try { $xml = new SimpleXMLElement($url,null,true); } catch (Exception $e) { continue; } if ($xml) break; } ?> The problem is: The failed grabs shoot an error message out each time! That is, when the line php:<? try { $xml = new SimpleXMLElement($url,null,true); } ?> code:
How do I make sure the try/catch actually does suppress errors and not bug the end user? I am fine with it failing 20 times, as long as it doesn't bug me with error messages and it, at some point, works. 20 failed attempts only delays the page by 2 seconds or so. EDIT: I think I found it! I just add the @ sign before "new" So @new cannibustacap fucked around with this message at 08:03 on May 26, 2009 |
# ? May 26, 2009 07:39 |
|
Also you can set error_reporting explicitly, so you don't have to supress each individual error that might occur.code:
|
# ? May 26, 2009 14:50 |
|
I'm trying to make a CMS for a Flash application that reads data from XML. I'm trying to use DOM PHP (it seemed a little more legit than SimpleXML when I started). Reading and displaying XML with DOM is easy enough, but is there a simple way to edit it? Obviously I'm still pretty new to PHP, but I understand enough about the various DOM objects and methods I think, so it shouldn't be too hard to help if anyone can. Also if anyone knows of a better way to manipulate XML, I'm open to that as well. Thanks!
|
# ? May 26, 2009 17:29 |
|
usingpond posted:I'm trying to make a CMS for a Flash application that reads data from XML. I'm trying to use DOM PHP (it seemed a little more legit than SimpleXML when I started). Use the DOM XML Methods for editing to edit it? What exactly are you having trouble figuring out what to do?
|
# ? May 26, 2009 18:47 |
|
Lumpy posted:Use the DOM XML Methods for editing to edit it? What exactly are you having trouble figuring out what to do? Well basically, I wanted to edit a child from this: code:
code:
|
# ? May 26, 2009 22:02 |
|
usingpond posted:Well basically, I wanted to edit a child from this: I have no idea if you are using PHP4 or 5, here's a 4 example php:<? // assume you've read in the XML to $myXML $root = $myXML->document_element(); $parentTag = $root->first_child(); // you could skip this and do it directly below, but to be clear. $childTag = $parentTag->first_child(); $childTag->replace_child("DIFFERENT INFO",$childTag->first_child()); ?> php:<? $myXML = new DOMDocument(); $myXML->loadXML('<root><parent name="parent"><child>info</child></parent></root>'); $xpath = new DOMXpath($myXML); $nodelist = $xpath->query('/root/parent/child'); $kidNode = $nodelist->item(0); /* you could also have done: $kidNode = $myXML->firstChild->firstChild->firstChild; */ $newContent = $myXML->createTextNode("DIFFERENT INFO"); $kidNode->replaceChild($newContent,$kidNode->firstChild); echo "<PRE>"; echo htmlentities($myXML->saveXML()); echo "</PRE>"; ?> Lumpy fucked around with this message at 00:46 on May 27, 2009 |
# ? May 27, 2009 00:26 |
|
You are a drat nice guy! I am using PHP5, so thanks a bunch. Works great, by the way! Tron Paul fucked around with this message at 18:03 on May 27, 2009 |
# ? May 27, 2009 15:46 |
|
I'm working on some PHP code some old guy set up here at work. I hadn't looked at anything PHP until two days ago, so I'm still fairly new to this. I came across this and it didn't look right. Also, I don't think it's working as intended. Please shed some light on this. This function is called in one part of a file: executefootagetransaction(false); Here's the function signature: function executefootagetransaction($zero, $consumeroll = false) Firstly, if you're going to call a function, don't you need to supply both arguments? Secondly, what is that $consumeroll = false nonsense in the signature?
|
# ? May 28, 2009 14:55 |
|
Jreedy88 posted:I'm working on some PHP code some old guy set up here at work. I hadn't looked at anything PHP until two days ago, so I'm still fairly new to this. I came across this and it didn't look right. Also, I don't think it's working as intended. Please shed some light on this. Firstly, no. Secondly, that's how you make it so you don't have to supply all the arguments. In PHP, and many other languages, you can set arguments to default values, so taht if the argument is not supplied, it's set. Here's fun made up code to learn you: php:<? function blah($name="Dave",$msg="Sup d00d") { echo "Hey $name, $msg"; } blah(); // "Hey Dave, Sup d00d" blah("Larry"); // "Hey Larry, Sup d00d" blah("Skippy","you suck"); // "Hey Skippy, you suck" ?>
|
# ? May 28, 2009 15:14 |
|
Lumpy posted:Firstly, no. I figured it was something like that. Thanks for the information.
|
# ? May 28, 2009 16:05 |
|
Out of curiosity, is there any way to skip the first argument in that? So like...php:<? blah(,"you suck"); // "Hey Dave, you suck" ?>
|
# ? May 28, 2009 17:24 |
|
Golbez posted:Out of curiosity, is there any way to skip the first argument in that? So like... I do not say this with 100% certainty (but like 99.8%), but no. You can't pass over arguments.
|
# ? May 28, 2009 18:18 |
|
|
# ? Jun 3, 2024 22:33 |
|
Lumpy posted:I do not say this with 100% certainty (but like 99.8%), but no. You can't pass over arguments. I say it with 100% certainty. You can not do that. You could do like blah(null, 'crap'); or blah('', 'dongs');
|
# ? May 28, 2009 18:24 |