Jump to content

requinix

Administrators
  • Posts

    15,066
  • Joined

  • Last visited

  • Days Won

    414

Everything posted by requinix

  1. RedirectMatch (not Redirect) can do it, and is what I would use. RedirectMatch ^/article/ /index.phpRewriteRule can too, of course. Basically the same thing as above. RewriteEngine on RewriteRule ^/?article/ /index.php [L]
  2. There's no way to get one regex to do that because (1) can't match more than one thing in a collection of other things, and (2) can't get array keys like that. imperimus's solution is basically how you have to do it, though there's flexibility on exactly how of course: 1. Match all the OBJECTSTART to OBJECTEND "tags" and loop over each 2. Match all key=>value pairs inside each tag and loop over each 3. Add to an array
  3. I'm actually going to add another process into the mix. With that in mind, here's what I was trying to describe: - There is more than one process [1] running, each one having its own dedicated purpose - Each client that connects gets its own process that is oriented towards supporting communication with the client - There is a "socket server" that monitors each client process; it is the process that has the original socket that people connect to, but when they connect it creates a child to handle it rather than do the work by itself - The socket server will often relay messages to and from a client process - There is a process for each thing ("handler") that needs to run on ticks, and it can communicate with its managing process - There is a "tick server" process that monitors each tick handler: it counts out the ticks and tells each child when a tick happens - Likewise, the tick server will often relay messages to and from a tick handler - (New) There is a "game server" process that deals with the game itself, and is what people would generally call "the server" when they're talking about this game - The three server processes can communicate with each other Here's an example of how it all works together. Let's take an MMO as an example: - Game server starts and does whatever it needs to do (eg, initialize state, set up environments, whatever) - Socket server starts and waits for connections - Tick server starts and launches processes for all the tick handlers it has - Tick handler #1: deals with the time of day, like it tracks when "day" and "night" happen: 1. When it starts it queries the game server for state and is told it is daytime - or is told the in-game time, or whatever 2. It runs, sleeps, runs, sleeps, and so on, waiting... - Tick handler #2: resources regenerate 1 unit per 120 ticks (60s) 1. When it starts it sets a counter to 0 2. Every tick the counter increments 3. When the counter reaches 120 the process issues an update [2] and resets the counter to 0 - Now, a user connects: 1. They connect to the socket server 2. The socket server accepts the connection, spawns a child process for the client, and goes back to waiting for connections 3. The child process has the user authenticate and whatever, and informs the game server (via the socket server) 4. The game server sends information back about the client, blah blah blah - As the user acts, the client processes sends information to the game server, which acts accordingly - Meanwhile the tick handler has been executing, however it's currently daytime (as it was told by the game server) and nighttime hasn't come yet - Eventually the tick handler detects a change to nighttime: 1. It sends a message to the game server (via the tick server) regarding the change 2. The game server updates itself 3. It then sends a "broadcast" message to the socket server to inform all clients of the change (by basically just passing the same message along to everyone) - The user doesn't like playing during the dark and rage-quits: 1. The client process discovers the connection died 2. It passes a message to the game server (via the socket server) that the user disconnected 3. Game server updates accordingly However as I explain this I realize I'm not a fan of ticks. Personally I would go for an event-based system since ticks can be simulated through sleeping: - Daytime tick handler sleeps for however long day-/nighttime is, wakes, sends an event to update, and goes back to sleep - Resources tick handler sleeps for a minute at a time So questions for you: 1. Have more details about what this game (I presume) system is for and what it does? 2. What do you need ticks for? And disclaimer: I know enough about socket programming and multi-threading/-processing to think I know what I'm talking about. You should also look for resources written by professionals. [1] Again, because forking is easier to explain. The threading model is similar enough. [2] Few possibilities. My first thought would be, essentially, executing an UPDATE query on a database, then informing the game server that resources have expired. This is slow. Faster would be having everything in memory, but I'm not knowledgeable enough to know how to pull that off well. (Shared memory, maybe?)
  4. As you should be able to see in the error message, you aren't actually specifying a username or password. You need to do that.
  5. Right, a server. (Using forking terminology because that's easier to explain with:) The server shouldn't be doing any actual work. It just spawns children and tracks ticks. I'd use two servers for that, actually, and a master daemon that creates and monitors those two. Master daemon forks and monitors socket server process; if running in the background, the initial process forks and dies and the child becomes this master daemon Socket server sets up listening socket and waits for children Upon connection, server forks and monitors a child process for that connectionChild process communicates with the client Master daemon forks and monitors tick server process Tick server forks and monitors tick handler processes for each thing that has a tick action Tick handlers sleep while they wait for a tick When they wake, perform action, then go back to sleep Tick server sleeps for ticks, wakes children (via socket or signal) when a tick happens There's a socket pair between: - Socket server and tick server - Socket server and each client child - Tick server and each handler child Follow so far? As for threads, if you can then that's better than forking processes. Overall scheme is still the same but the technical details, like forking and socket pairs, are different. Threads are also quite a bit different to manage so you should read up on threading and (presumably) PHP's pthreads before you start trying to add it to your code.
  6. Please don't. usleep. $start = microtime(true); while(true) { // stuff $end = microtime(true); $remaining = 0.5 - ($end - $start)); if ($remaining > 0) usleep($remaining * 1e6); $start = $end; }
  7. That's the idea, but a JSON string like that is annoying. Instead do curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array( "t" => // timestamp, "secret" => // secret, "total_quantity" => // amount, "price" => // price )); It's for arbitrary headers. Said headers can be used for (some types of) authentication. You're supposed to take the request body (the json_encode()d stuff, from the code I just wrote), your private key, and run them through the "HMAC256". Unfortunately there is no such thing. I think they mean HMAC with SHA-256. hash_hmac("sha256", /* the request body */, /* your private key */)
  8. You don't reset _bind after the first query, thus the ->execute() branch in run() gets executed again. I suggest resetting (to false) in prepare().
  9. Can't use header() if there's been any output. The error message tells you where the output happened. You have to decide whether that output should be moved (and if so, where to), or whether there's a bug and your code wasn't supposed to header() at all, or something else.
  10. The logs aren't in MySQL... If you're going to administer a server then you need to learn how to administer a server, and one of the very first things you should learn is where log files are and how to read them. Familiarize yourself with the files in /var/log. And yes, Amazon RDS. It's their cloud database service. So you don't have to manage your own MySQL server.
  11. Have you tried to figure out why the service stopped in the first place? Checked MySQL and system error logs? Any reason you aren't using RDS?
  12. The harder way is restructuring your tables. Without knowing, well, anything about your application, my first thought would be Three tables. One of the user information: name, email, and password. And an ID, naturally. Then another table that has the user ID and potentially other things that may be useful and particularly pertinent. "Pertinent to what?" This table tells you which users are these "warehouse" people or whatever that's supposed to be. The third table is the same thing but for the "event host" people or whatever. Or maybe, The user table from before with an enum field of "warehouse" and "eventhost", like `type` ENUM("warehouse", "eventhost") NOT NULL,That way every user is definitely one thing or the other. Or you can use a SET to allow more than one. Or maybe, If there's a chance of having more than just "eventhost" and "warehouse" then maybe you need something where you won't have to change the schema. That tends to mean two or three tables. One table for users, no surprise. The second table relates a user (by ID) to a thing. That thing could be a string, like "eventhost", or it could be an ID to a third table which lists the different types (and would only have 1,warehouse and 2,eventhost to start).
  13. A blank screen (aka the White Screen of Death) is typically caused by a syntax error. Check your code to see if there are any mistakes. Such as missing a . concatenation.
  14. What exactly is "issues"? You get a line at the top of the table? The first image is in the right column instead of the left?
  15. "Typically"? Take the easy (easier) way out of this: do one query against eventhost, then if they're not there do a second query against wharehouse.
  16. The else is attached to the second if, and only that. Since $keyword doesn't contain "mickey", it executes. You need an else if: <?php $keyword=$_GET['show']; if (strpos($keyword,'house') !== false) { $image="housewives.jpg"; } else if (strpos($keyword,'mickey') !== false) { $image="mickey.jpg"; } else { $image = "default.jpg"; } ?>
  17. Thought so... When you do a UNION, you only get the column names from the first row. That means the ID from the wharehouse table looks like "hostId" and not "whId". As such you can't tell which table a row came from. A question before we continue: what should happen if an email address is present in both tables?
  18. The two lists: there are a few places you could store that information but the most appropriate is probably a database. Then you can add, change, or remove items at will without having to change any code. The looping: two loops, one on the outside counting the first half of the phrase and one on the inside counting the second half of the phrase. Or vice versa, it doesn't matter. The "wrapper": Google has an API you should use for that. I think they consider it part of the "custom search engine" stuff, but IIRC you can fiddle with it so that it acts like a regular search. The results: also go in the database.
  19. Use phpMyAdmin or MySQL Workbench or something to connect to your database manually. So that you can do things yourself, not through code. Find where you can run a SQL query directly and run those two queries I wrote. Then post the output of each. Or, alternatively, just tell me what the names of the columns are in both tables and what type of data (eg, VARCHAR or DATETIME) each one is. The SHOW CREATE TABLE queries I posted are a quick way of doing exactly that, but it's only quick if you can actually run the queries somewhere.
  20. ... What is the structure of the eventhost and "wharehouse" tables? Easiest way to answer would be with a SHOW CREATE TABLE: SHOW CREATE TABLE eventhost; SHOW CREATE TABLE wharehouse;
  21. //7 Retrieve Results from ResultSet $row = mysql_fetch_array($queryResult); That is where you get a row of data from the query. That row should have whatever value you need. Do a print_r($row);if you're not sure what's in it (hint: it mirrors the table columns). To redirect, you already have the header() so you just modify it accordingly. One thing, though: header() does not stop your code from executing, so since you actually want it to then you should exit;immediately after.
  22. Safest option would be one each, but what's important is that the value changes somewhat frequently.
  23. That's not something that happens without you specifically telling PHP to do it. So how did you set that up? Did you remember to do that on the Windows hosting?
×
×
  • 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.