Jump to content

Agum

Members
  • Posts

    14
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Agum's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, always wanted to know those little things..
  2. Thanks Barand. One more quick question. What is the best way to concatenate an array into one string (comma separated values)? Just loop through it and do $str .= ... ? Or is there a function? Thanks
  3. I have two questions regarding array. I would like to do the following in an efficient way. 1) I have two arrays. They contain ID numbers (unique). The first array has, say 100 elements. The second array has, say 20 elements. Every ID that appears in second array is also in the first array (guaranteed). What is the best way to search in the first array and remove every element that appears in the second array? 2) I have a multidimensional array/hash like this: arr[0]['id'] = 123; arr[0]['name'] = "John Doe"; arr[1]['id'] = 456; arr[1]['name'] = "Peter Smith"; ... I would like to "sort" this array based on the "name" part of the array. The id number needs to be kept with that particular name it comes with. What's the best way to do this? Thanks.
  4. I'm working on an interesting web app and here's a situation I'm going to get to: * User performs an action, which starts this "session"... * During this "session", user will be sending requests (performing actions) to the server every 3 secs, or 5 secs. These are AJAX (xmlHttpRequest) requests. * This could go on for 5~10 times before this "session" ends. (when I say "session", it has nothing to do with cookies, I just mean the word "session" in literal meaning) Now, due to the information needed to perform every action, each request would need to do a MySQL query, grab some information, then do some calculation, and write to the db. If we consider possibly large user traffic, then I'd want to do this as efficiently as possible. I can do this the normal way -- have xmlHttpRequest send to a php script, then it will go through and do all that needs to be done. (script begins -> SQL read -> processing code -> SQL write -> output to client -> script ends) Is there any ways I could make this more efficient? What I don't know is if it's possible to make it only one script execution, while it waits for new user actions. Effectively, this means: script begins -> SQL read -> processing code -> SQL write -> output to client -> wait for next event -> processing code, SQL write, output and repeat until last action -> script ends This saves 1 MySQL query for every action done, because only one read initially is needed for the entire lifetime in my specific case. However, how can this be done at all? The PHP script and the JS would need to have some kind of interaction, more than just the xmlHttpRequest. (because if a request was made, then it's starting a new php script execution) I thought about using cookies, having JS set some cookies for each action done, and have the php script read it every 5 secs -- but that creates sync'ing problem and I don't think JS can set cookies before the whole page refreshes, anyway. (was that totally confusing?)
  5. So I am working on this online system, and it employs an OO design for the most part. I was wondering for "utilities" functions, should I make another class for them or put them in the global scope? What are the advantages of each? Does it even matter? By utilities function I mean things like, a function that checks an email string for validity, and so on. Putting them in a class doesn't mean I'll make any objects, but just that I have to call it by Classname::func() every time, since they are just generic functions.
  6. Would it really do any difference in terms of performance? That's the real question -- since they are all methods definitions (implementations), technically if they aren't called, the code doesn't execute. So it should just be loaded in memory and nothing else, right? If that's the case, does that affect performance by much?
  7. thanks Wildbug. that's a good point - since it only needs to run at account sign-up, I guess it's ok even if it's a bit unefficient. mon.e.boy, if you have played WoW, you will know that character names allow 1 hyphen, and it cannot be in the first or last char, and you cannot have 2 hyphens consecutively. my sytem has similar rules except a few differences, such as allowing underscore, etc. * how do I mark this thread as SOLVED and change the icon?
  8. http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html typical MySQL can support around 500~1000 simultaneous connections. some can support up to 4000. but if you have a large web site like yahoo.com, that's certainly not enough. they probably get more than 4000 search queries a second.
  9. Oops, enclose the line $sep = ', '; within the previous if block. if($y == $z['Short']) { echo $sep,$z['Long']; $sep=', ';} that should fix it.
  10. for example, MySQL is not very good at handling large # of connections. If you have a super high traffic site and the project is huge, MySQL may not be able to handle it. (it's not just the # of connections, but also query execution times, etc.) I don't know that much about .NET, but I assume you use MS's SQL server with it usually. Pretty sure it can handle a higher load than MySQL.
  11. actually sasa is almost right, just need a slight change... try this $sep=''; foreach ($page['references_amenities'] as $z) foreach ($APPLIANCES as $y) { if($y == $z['Short']) { echo $sep,$z['Long'];} $sep=', '; }
  12. as far as I know, .NET might be actually more reliable. Or maybe I should say scalable. for extremely large projects and/or extremely high traffic web app, I think it would be reasonable to go with .NET actually. but every other reasons you stated is right. PHP and MySQL are free, open-source, have a large community to support it (thus having fewer dangerous bugs), cheaper to do development on, and probably a bit faster than .NET. it's easier to setup too. even on my own WinXP pc, it took little time to setup Apache, MySQL and PHP on it with no problems.
  13. I need a RegEx pattern that checks for usernames. The username must consist of only alphanumeric characters or hyphen (-) or underscore (_). The thing is, hyphen or underscore must have an alphanumeric character before and after it. Test cases: Spiderman = ok Spider-man = ok Spider_man = ok Spider--man = err Spider__man = err -Spiderman = err Spiderman_ = err Spider-man-2 = ok 1_Spider-man = ok me and my friend came up with two different ways to do this: ^[a-zA-Z0-9]+([-_][a-zA-Z0-9]+)*$ matches the "good" stuff (return true on OK, return false on ERR) ^[-_]|[^a-zA-Z0-9-_]|(--)|(-_)|(_-)|(__)|[-_]$ matches the "bad" stuff (return true on ERR, return false on OK) which one would be more efficient? if they are both pretty bad, do you have a suggestion for a better way to do this? also, what's the difference between preg and ereg in php? which one do you recommend and why?
  14. I'm working on a project and I anticipate the traffic to be fairly high when it's done. There is almost no static pages so every page hit is a php script execution basically. Because the application is fairly complex, I am designing it in an OO approach. Some core classes will get fairly large when they are done -- maybe 100kb~ each for 2 of the classes' code (initial version). These are the core objects that are used by basically every php script. (and as time goes, there'll be more enhancements so it can only increase more) Is efficiency/server load/running time something I should have to worry about? It's a very interactive web application (employing a lot of AJAX, and even full page loads are fairly frequent) for every user, and I anticipate to have hundreds of users at the beginning, soon to grow to thousands. With source files/classes of such sizes, do you think that's an issue? (the point is, every interaction requires loading all these classes [probably 4~5 classes], executing at least a few methods in each) (I'm not really extremely familiar with how PHP handles memory management and code execution, so maybe something of this size is entirely reasonable and not a problem. I just want to know.)
×
×
  • 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.