-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
webcam - use PHP to grab mjpeg from webcam or a single frame
kicken replied to fsusr's topic in Third Party Scripts
Your're probably corrupting the stream with the way you're doing it now. Also if the webcam never closes the stream, your script will never end, thus the reason why it's always "waiting for host." What I would do is first of, try just outtputing the proper Content-type: header using header and then use readfile with the URL of the webcam. If that does not work, then you'd probably need to figure out how to extract a single jpeg from the stream and output that. -
Is it possible to redirect from ftp to http?
kicken replied to eurusd's topic in PHP Installation and Configuration
No, FTP does not have any redirection capabilities. -
Placing a %s in your query is not the proper way to indicate where a value should be substituted at. [Re-]read the manual on PDO::prepare and [Re-]read my example code above.
-
Doing Quick Saves Via PHP/Client Side for Turned Based Game?
kicken replied to Monkuar's topic in Application Design
Who said anything about cookies? Obviously you wouldn't store your game data in a cookie, that is just asking to be hacked. -
You're missing a . in there.
-
I like this new round of updates much better than the previous update. After clicking around a bit I can't see anything that I don't like really. The font seems fine to me, but I've never been too picky about such things.
-
Do only one query that pulls all the data, rather than a bunch of queries. Relevant reading: Building Tree Structures In Php Using References
-
Yes. How depends on where your data comes from. If you're using Mysql and have a query to return the data, just add in a GROUP BY clause and SUM() function. Otherwise group the data into an array in PHP with a total variable for each group.
-
You need to create a function which will locate all the desired textboxes and then loop through them totaling the values. Then just call that function from whatever events you want to trigger the summation. If you use jQuery, this would be fairly easy to do: function sumInputs(){ var total = 0; $('input[name="ltotal[]"]').each(function(idx,ele){ total += +ele.value; }); alert(total); } If you are not (and/or dont want to) use jQuery, you'd need to write a bit more code to locate the correct elements, and use a for loop to go through them. Something like document.getElementsByTagName('input') to get each input, then a for loop and test each input's name to see if it matches "ltotal[]" and if so, add it's value to the total.
-
You need to use parenthesis to force the order of your conditions. Right now, that statement will be evaluated like this order: (ON_SALE = 'Y' and SUB = '159') or SUB = '111' or SUB = '71' So as long as either sub=111 or sub=71 is true, the entire condition is true. The ON_SALE=Y condition is attached only to the SUB=159 condition. I'm assuming you want that ON_SALE=Y to be required regardless, but sub can be any of the values. You need to use parenthesis around the OR conditions to ensure they are evaluated first, then only if they are true, the on_sale=y is evaluated. ON_SALE = 'Y' and (SUB = '159' or SUB = '111' or SUB = '71')
-
Running MySQL Query with Union (2 SELECT) on PHP
kicken replied to cary1234's topic in PHP Coding Help
What kind of a problem are you having? You process a UNION query the same way you'd do any select query. No special handling is necessary. -
Doing Quick Saves Via PHP/Client Side for Turned Based Game?
kicken replied to Monkuar's topic in Application Design
I just mean some kind of in-memory variable that would be accessible to all clients. Attached is a very quick-n-dirty example of what I mean by having your own server with some kind of global storage. You'd have to put a lot more thought and work into this to make something that functioned well for real-use, but this should illustrate the idea. chat.zip -
Something like this would work as a one-liner swap: list ($b,$a) = array($a, $b); Otherwise, you'd use a temp variable as in: $a = 'foo'; $b = 'bar'; $tmp = $a; $a = $b; $b = $tmp;
-
Doing Quick Saves Via PHP/Client Side for Turned Based Game?
kicken replied to Monkuar's topic in Application Design
You need to change how you think about the server-side of things. For instance, rather than using apache as your webserver and running individual PHP scripts for each request, you would use PHP itself as your webserver and have some kind of global store to manage character and mob data. This eliminates the need to query the database on each request as you can just look at what is currently in the global store. You could then setup some kind of system to save important details from that global memory storage to the more permanent database storage periodically. For example maybe once a second or once every x requests or something. -
Curious if I should move to Socket.io for this
kicken replied to Monkuar's topic in Application Design
Yes, it's the same thing. No, it's probably not saving any resources. It also has nothing to do with socket.io really. Socket.io is nothing more than a way for the browser and your server to communicate with each other. If you want to use less resources on your server, you need to design your scripts to use less resources. Socket.io will not help you with this problem, because it is not a problem that socket.io is attempting to solve. edit: You posted this in the wrong forum. I've moved the thread to a more appropriate forum for you. -
You only need one query: SELECT * , TIMEDIFF(job_end, job_start) AS job_time , users.first_name AS int_name , users.last_name AS int_last , users.rate AS int_rate FROM jobs LEFT JOIN users ON jobs.contractor_id = users.id WHERE job_date BETWEEN ? AND ? AND contractor_id = ? AND entry = 1 ORDER BY job_date ASC , job_start ASC Queries in loops like you have right now are generally a bad idea and begin to kill your app's performance, even at only a few loop iterations. You also should not be using * in your select list. It also will hurt performance by selecting unnecessary data, and also makes the queries less friendly by requiring you (or someone else) to reference the database table structure to find out what data is being returned from said query. Lastly, your query in get_jobs has a syntax error in it. There is an extra , before FROM.
-
By a persistent socket I mean you connect once, then just send data to/from the server, rather than constantly connecting/sending/receiving/disconnecting which is what http normally does. Having a constant connection allows the server to be able to push data to the browser when it is necessary, rather than the browser having to constantly check in with the server to see if anything has changed. If there is no changes, no data is sent saving bandwidth and processor power. As far as querying the chat table, that all depends on how you want to setup the server side of things. You could just have your server setup so that when someone sends a message, the server accepts it and then re-distributes it to all connected clients and never even involve a database table. This is how IRC works for example. If you wanted to store a complete chat history then you'd still need to write it to a table, but you only need to write it, not re-select it for each client. # of rooms is irrelevant. # of connected clients is what you need to be concerned with. 1 room with 100 people is the same load as 10 rooms with 10 people each, more or less. How many clients your server would be capable of supporting depends on how well the chat software is coded and server specs. A low-end VPS (512-1gig ram) should easily be able to handle a few hundred users. Depending exactly on what you need/want the chat to do obviously. Possibly, although just because the client disconnects does not mean the server would fail to save the data. For that to happen, something would have to happen on the server end, such as a crash or power outage. Also you need to keep in mind that these big MMO's you compare to have LOTS of servers, possibly with some pretty high-end specs. Also, keep in mind that a lot of the interaction with the database is going to be SELECT queries, just reading out things like character/mob specs, loot tables, etc. There would be quite a bit fewer write operations going on. To handle all the SELECT's you use replication to distribute the load among several different slave read-only DB servers. Write operations would be directed at the master server which then relays those changes to all the slaves. Every piece of windows software that connects to a network at all uses winsock. Winsock is windows' sockets implementation which drives all socket base communications.
-
You could farm the processing out to a dedicated machine (or multiple machines) if the need was there. Until you hit a massive scale though, just running the process on the same machine would suffice. PHP limits it's own memory consumption. Just because you hit a limit in PHP does not mean that the system cannot do more. If you do reach a point at which the system is overloaded then yes, the answer is just "throw hardware at it" by adding additional servers, either as dedicated image processors, or just additional web servers to distribute the load.
-
Handle the image operations external to PHP. For instance, exec() out to ImageMagick or similar. PHP's memory limits and other restrictions do not apply to external processes. Such programs may also have better optimizations and do the job quicker.
-
From what I gather reading the documentation, the new partition select syntax would only improve your performance if your partitioning is setup in such a way that you can ignore safely ignore some partitions. For instance if you partition by year, but are only interested in this years data, you could limit mysql to only searching this years partition. In addition to asking/searching around for other peoples opinions, you would probably be best served by downloading and installing mysql 5.6, importing your data, and playing around with it to see how it performs. Given the newness of mysql 5.6, and the specific nature of your inquiry, finding existing relevant opinions/benchmarks may be a bit challenging.
-
I would imagine (but have no pratical experience/knowledge) that a game server most likely handles a lot of the operations/changes that need done in-memory and has some kind of background thread which will periodically save changes to the database. That way it would be able to service all the clients quickly without waiting on the database. No, socket.io is just a wrapper for various ways of establishing "real-time" two-way communication. Exactly what it does depends on what the browser/server supports. A modern browser with Websocket support would just keep one persistent socket open to send data through. A browser Flash support uses some small flash program to emulate websockets. A browser with XHR will use either long or short polling, depending on what your server supports. This ability for socket.io to adapt to what is available is why it is popular. It will use the most efficient method it can while keeping a constant api for your application to use. Sure, you'd just have a lot of unnecessary requests constantly checking on things. If it is the only method available though, then that is what you do.
-
Replace utf8 character in a certain position of a string
kicken replied to filoaman's topic in PHP Coding Help
$str = substr_replace($str, "i", 2, 2); If you read about the UTF8 encoding, you'll notice that a single character can be stored as anywhere from 1 to 6 bytes. In the case of î, it is using 2 bytes so you need to use a length of 2 in your substr_replace. -
It works for now. Before you go any further, you need to re-write your code using Mysqli or PDO to connect to your database. The mysql_* functions are officially deprecated and slated for removal. Once that happens, your code will no longer work. I prefer PDO, so my examples will use that. Each API provides a function to return the last insert id. All you need to do is call that after your insert: $sql = 'INSERT INTO blog_post (title,post,author_id,date_posted) VALUES (?,?,?,?)'; $params = array($_POST['title'], $_POST['post'], $_POST['author'], time()); $stmt = $db->prepare($sql); $stmt->execute($params); $blogPostId = $db->lastInsertId(); First, run a SELECT query for the tag to try and locate it in the database and fetch it's existing ID. If it is not found, then run an INSERT to add it and use the lastInsertId method to get it's new ID. Save each ID to an array so you can later add the appropriate records to link the blog post. $sql = 'SELECT id FROM tags WHERE name=?'; $fetchstmt = $db->prepare($sql); $tags=array(); foreach (explode(',', $tagString) as $tag){ $fetchstmt->execute(array($tag)); $tagId = $fetchstmt->fetch(PDO::FETCH_COLUMN,0); $fetchstmt->closeCursor(); if (!$tagId){ //Do insert //Call lastInsertId } $tags[] = $tagId; } //Loop through $tags, add entry to blog_post_tags for each one There is no need to be keeping a count of the times a tag is used. You can determine that with a simple query on the blog_post_tags table with GROUP BY and COUNT(). SELECT tag_id, COUNT(*) as numTimeUsed FROM blog_post_tags GROUP BY tag_id
-
If you get bad request, most likely your PHP is never even running. Your server may have some kind of filter enabled to reject requests with the smart quotes in them. Check your server's error logs to see if you can get a more detailed reason why the bad request error occurs.
- 3 replies
-
- quotes
- bad request
-
(and 3 more)
Tagged with: