Jump to content

gizmola

Administrators
  • Posts

    5,945
  • Joined

  • Last visited

  • Days Won

    145

Everything posted by gizmola

  1. The guy who started phpfreaks has a hosting company that has been around for many years. http://www.serverpowered.com/
  2. gizmola

    Yo everbody

    It couldn't hurt, but the main thing is, to get started trying to create a php script that does something.
  3. Haha, well my kids agree that I'm scary, especially when I'm chasing them around with an ERD diagram in hand.
  4. PHP is a 2 tier architecture. You have the web clients and they talk to the webserver which has PHP built in. So once you need to scale there are a lot of different strategies involved. Here's some things to consider: -Front end performance and overhead of apache When your application is running, it needs memory, and this becomes a limiting factor on the webserver. If apache can not fork new child process memory out of available ram, the machine starts swapping, and things get slow fast. -Database performance: There are plenty of bottlenecks that can occur here including, IO performance of the db machine, locking bottlenecks, and other issues that I can't explain in a soundbite. The database engine, and the specific design of the system directly impact these issues. There is no magic bullet list of items I can give you, however, it tends to be that most large PHP/MySQL based sites tend to use a Reader/Writer architecture. This often works because web apps are often skewed to have a high ratio of read to to write activity. Using mysql replication you can spread the load out, and have an array of "reader" mysql db's that can be used for selects. When there is insert/update activity, then the readers are used. Caching is also a pretty essential scaling activity. Many large sites like Facebook make use of memcached to cache database reads in memory. Memcached is a distributed cache, so they have invested in arrays of machines that are basically cpu+memory+network servers, and do nothing other than serve as memcached machines. The individual apache/php servers are configured to know about the memcached cluster, and get data from it as much as possible to minimize db load. In regards to db design there are some obvious concerns: - Keys. You need a scheme for assigning keys so that you can move individual rows around without causing key collisions. If I have db1.user and db2.user and I use auto_increment, I willl then have 2 users with user_id = 1. This is a problem for scaling, so people have to come up with something different. There are a lot of different approaches, but one I've seen frequently is the use of a GUID as the primary key for rows. PHP sessions are by default local files on the server. Once you have a cluster, the session data can no longer live on a single server if there's any possibility that someone might be routed to a different apache/php server for load balancing purposes. So you need to have an alternative serialization mechanism. People frequently use either the database, or memcached for session storage. Unless you have a really clear cut idea of how to develop this from scratch I would certainly recommend using a framework that provides you an MVC implementation. Many people also welcome the use of an ORM component that provides database abstraction. Setting up an infrastructure and maintaining it, requires some really good sysadmin skills. Hopefully you will be able to find someone to aid you there. Zend Framework or Symfony are both frameworks you should take a serious look at for a project like this. That's all I can think of off the top of my head. Good luck with the project.
  5. Using the ternary is an alternative to a simple if - then -else. If it's not an if - then - else, then it's not going to be translatable to a ternary.
  6. gizmola

    Hi guys

    Hi. Just to let you know PHP is really nothing like c++ at all. It shares some syntax with c, javascript and perl, and in version 5 and 6 has started to borrow some things from Java. The important design ideas behind PHP: -It can be intermixed easily with HTML/markup languages -It's parsed and interpreted on the fly -It is a loosely typed language, meaning that variables don't have to be declared before they are used, and can change datatype via automatic typecasting without you having to cast the values or convert them in your code. -It has a well defined api that allows external libraries to be integrated quickly and easily. This accounts for its utility.
  7. Yes, I have done things like this many times. Typically you write the php script that you call from a cron job which runs it on a set schedule, using command line php: php -f checkfornotify.php I have written several articles on using the various date columns along with builtins to determine date ranges offset from right now: http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html http://www.gizmola.com/blog/archives/99-Finding-Next-Monday-using-MySQL-Dates.html What is your specific question?
  8. Databases wouldn't be very useful if you couldn't provide criteria to them and get back result sets. Fire up your mysql command line or phpMyAdmin and do some queries so you can understand the process. I don't know what your table name is, so I called it usersummary in this example: SELECT * from usersummary WHERE Lost = 4 ORDER BY XP
  9. Huh? What I provided was the actual implementation details you would need to do what was described in btherl's reply.
  10. When you're fetching the rows, just use a variable that you increment whenever the $row_board['percentage'] is greater. $rank++; $lastpct = $row_board['percentage']; } ?> %
  11. I don't know what you have for a query at this point, but I can tell you that the original query is invalid. UPDATE ecomm_orders_details SET feedback = "1", WHERE order_id = "1" The comma is invalid. The query should be: UPDATE ecomm_orders_details SET feedback = '1' WHERE order_id = 1 I'm actually not even sure if this is correct because it depends on the datatype of the feedback column. If things are "strings" you put quotes around the values. If they are numbers, then you don't. Regardless, you can't have a comma hanging out there, commas only go in the list of columns or values part of a query. For update queries it would only be in the SET part of the query if you're updating multiple columns.
  12. Here's the ERD diagram for the tables:
  13. http://www.php.net/manual/en/function.simplexml-load-file.php or load-string(). If you read the manual comments for this page there are multiple implementations that people posted of converting the simplexml object to an array.
  14. Some years ago I developed a survey product with some other people, and started a company around it. You can really get a complicated design for a tool like that. I'm not going to go to that extreme, but I'll give you a simplified db design that is typical of these apps. # ---------------------------------------------------------------------- # # Tables # # ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- # # Add table "poll" # # ---------------------------------------------------------------------- # CREATE TABLE poll ( poll_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, creator_id INTEGER, question VARCHAR(255), description TEXT, createdOn TIMESTAMP, CONSTRAINT PK_poll PRIMARY KEY (poll_id) ); # ---------------------------------------------------------------------- # # Add table "pollChoice" # # ---------------------------------------------------------------------- # CREATE TABLE pollChoice ( poll_id SMALLINT UNSIGNED NOT NULL, pollChoice_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, choice VARCHAR(255), CONSTRAINT PK_pollChoice PRIMARY KEY (poll_id, pollChoice_id) ); # ---------------------------------------------------------------------- # # Add table "pollAnswer" # # ---------------------------------------------------------------------- # CREATE TABLE pollAnswer ( poll_id SMALLINT UNSIGNED NOT NULL, pollChoice_id MEDIUMINT UNSIGNED NOT NULL, user_id INTEGER UNSIGNED NOT NULL, answeredOn TIMESTAMP, CONSTRAINT PK_pollAnswer PRIMARY KEY (poll_id, pollChoice_id, user_id) ); # ---------------------------------------------------------------------- # # Foreign key constraints # # ---------------------------------------------------------------------- # ALTER TABLE pollChoice ADD CONSTRAINT poll_pollChoice FOREIGN KEY (poll_id) REFERENCES poll (poll_id); ALTER TABLE pollAnswer ADD CONSTRAINT pollChoice_pollAnswer FOREIGN KEY (poll_id, pollChoice_id) REFERENCES pollChoice (poll_id,pollChoice_id); If you're using myisam the constraints aren't going to matter, and can be stripped out. This will perform well for most queries because there are covering indexes. I made the relationships defining, which offers the convenience of not having to join the tables together in many situations. You would probably need an index in the pollAnswer table that is on user_id. Of course the existence of user_id assumes you have a user system and you might need to tweak or change those columns to fit what you have. The important thing is that you have to link in those tables to the user who creates the poll and the one who answers it.
  15. Change your query to get you a random row: $getPet = fetch("SELECT * FROM pets2 WHERE id = '$array[species]' AND game = '$game' ORDER BY RAND() LIMIT 1");
  16. There is no best approach in these matters. I try and think about maintainability and use code that most clearly represents the logic of the application. With php there is one concept that comes up, and that is variable type. Because PHP will typecast variables on the fly, people rarely think about this, but there are times when you make your code more robust by checking not only the boolean value of a variable, but also it's type. So for example, there are cases where instead of using: $retval = somefunction(); if ($retval == false) { // error } else { // good } Your code will be more reliable if you have instead: $retval = somefunction(); if ($retval === false) { // error } else { // good } In the first case if the function returns 0, it will evaluate to false and the error section will be triggerd. This might not be what you want to happen, as zero might in this context be a valid retval. If you only want to enter the error section if the function explicitly did a "return false;" then you want to use the "===". I also try and use switch() {} blocks as much as possible rather than long if then else blocks.
  17. Let's say I'm an expert in the javascript language who doesn't know anything about electrical engineering. Would someone expect me to code up an application to be used by EE's to figure out the conversion of watts to amps? Programmers are expected to be able to work with domain experts to create applications that use the expert knowledge, or to research these areas themselves. In my experience good programmers are expected to be quick studies. They aren't expected to be Leonardo DaVinci or Albert Einstein. Plenty of domain experts end up writing software, using what they know, and learning how to program well enough to be able to translate their expertise into useful software as well. It doesn't mean that they write good efficient maintainable code.
  18. No it's not just you the same thing happened to me. When you look at the far right top of the page, there's a little arrow widget that folds an accordion div which hides that. Something happened to the site that closed that for people, or at least it did for me. Once you click it to open it back up you'll see the links again.
  19. You seemed to miss the point of Eran's post entirely, which was that the specific use of the superglobs make the implementation inflexible and non reusable, not to mention, impossible to unit test with the available php unit testing frameworks (phpunit and simpletest).
  20. Typically I'd expect to see a user class, with a login method. There are way too many books about OOP out there, but one that focuses on "Design Patterns" might be helpful.
  21. Glad we helped. If you get the chance you can mark the topic "Solved" by clicking on the "Mark Solved" button at the bottom of the thread.
  22. Not if you want it to not have to do a traditional post. With that said, there's a nice project that should help you out: http://jquerymobile.com/
  23. You can still take advantage of unix timestamps to handle these types of problems. // Current Unix timestampdefine('SECONDSPERDAY', 60*60*24);$nowTS = time();// Your old date$oldTS = mktime(0,0,0,1,1,2004);// Date of your old date - 30$oldTS30prior = date('m-d-Y', $oldTS - (30 * SECONDSPERDAY));$daysSince = ($nowTS - $oldTS) / SECONDSPERDAY;echo 'Today:' . date('m-d-Y', $nowTS);echo ' 2004 date: ' . date('m-d-Y', $oldTS);echo " -30 days: $oldTS30prior ";echo " Days from 1-1-2004 to now: $daysSince";
×
×
  • 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.