scootstah
Staff Alumni-
Posts
3,858 -
Joined
-
Last visited
-
Days Won
29
Everything posted by scootstah
-
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
You can use these to determine how to optimize queries: https://dev.mysql.com/doc/refman/5.6/en/slow-query-log.html https://dev.mysql.com/doc/refman/5.6/en/using-explain.html Make sure dt_username_member and dt_year are indexed. You still need to be using pagination though. -
Try echo json_last_error_msg() after json_decode()
-
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
Absolutely, but it does matter from a database design perspective. Well, when you build your calendar you would just see if any array items existed for that date. In pseudo code it'd look something like: workouts = array( '09-01-2015' => array( array('id' => 1, 'workout_type_id' => 1, 'bodypart_id' => 1, 'activity_id' => 1), array('id' => 2, 'workout_type_id' => 1, 'bodypart_id' => 2, 'activity_id' => 2), ), '09-02-2015' => array( array('id' => 3, 'workout_type_id' => 1, 'bodypart_id' => 1, 'activity_id' => 1), ), ) for each day month = 09 day = 01 year = 2015 if exists workouts[month-day-year] for each workouts[month-day-year] print workout Does that make sense? If not I'll give better example. -
It's probably because you're linking to a .html page. You can't run PHP from an .html page. Rename to .php and you should be good to go.
-
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
Okay, so why would the user want to type in their workout every day? Wouldn't it be better to select from a list? They could also create their own, which would be saved to its own table unique to that user, where they could then select from a list the next time. So where does that ID come from? Why not just store the ID and build the URL when you display the link? If you ever change your URL you're going to have to do a huge search & replace operation in the database. I think this might be a good start: member --------- id | name --------- 1 | bob bodypart ------------- id | bodypart ------------- 1 | arm 2 | leg 3 | chest workout_type ----------------- id | workout_type ----------------- 1 | strength 2 | volume 3 | dayoff activity ------------- id | activity ------------- 1 | Lower Body 2 | Push 3 | Pull workout ------------------------------------------------------------------------- id | date | workout_type_id | member_id | bodypart_id | activity_id ------------------------------------------------------------------------- 1 | 09-01-2015 | 1 | 1 | 1 | 1To get multiple results for the same day, I would probably fetch all of the data and then format it based on the day. So that you end up with a structure like this: array( '09-01-2015' => array( array('id' => 1, 'workout_type_id' => 1, 'bodypart_id' => 1, 'activity_id' => 1), array('id' => 2, 'workout_type_id' => 1, 'bodypart_id' => 2, 'activity_id' => 2), ), '09-02-2015' => array( array('id' => 3, 'workout_type_id' => 1, 'bodypart_id' => 1, 'activity_id' => 1), ), )Now you can easily access this information when building your calendar. -
It would seem that either $name, $email, or $message is in fact empty. You could try dumping the $_POST variable at the top, after form submission, to check what values it sees. echo '<pre>' . print_r($_POST, true) . '</pre>';
-
Well, you need to model this for a relational database and not for a spreadsheet. Here is a basic schema example: category ---------- id | name ---------- 1 | attendance 2 | contribution question ---------- id | question ---------- 1 | Attend more than 5 times? 2 | Attend more than 20 times? form ---------- id | name | quarter | year ---------- 1 | Form 1 | 1 | 2015 2 | Form 2 | 2 | 2015 3 | Form 3 | 3 | 2015 4 | Form 4 | 4 | 2015 user ---------- id | name ---------- 1 | James 2 | Gates result ---------- id | form_id | category_id | question_id | user_id | points ---------- 1 | 1 | 1 | 1 | 1 | 2 2 | 1 | 1 | 1 | 2 | 3Then you can use a simple query to get the number of points for each user:select sum(points) from result group by user_id;You could additionally group by category, question, or form.
-
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
Okay, so sounds like "dt_data" is really the exercise, so that can be its own table as well. What's up with the dt_wkurl, what is the point of that? -
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
Okay, so you're definitely going to want to break that into multiple tables. You're using a relational database, not a spreadsheet. I'm not sure that I have enough information on your business rules or data needs at this point to really make an appropriate model. The process of database normalization is to remove duplicated or repetitive data from your table and move it to another table, and then reference it with a foreign key constraint. For example the column "dt_bodypart" - I imagine that your rows will probably have duplicate data here... "arm", "arm", "arm", "leg", "leg", yeah? If that's the case, you could have a "bodypart" table where a row is inserted for each body part, and then you reference it via ID in your other table, and you then JOIN it to get the result. I've made an example here: http://sqlfiddle.com/#!9/8e10e/1 Some other columns that could probably be normalized: - dt_username_member - dt_wktype - dt_custom_event What is dt_data? What kind of "data" does that hold? It could also help if you provided a small dump with like ~20 rows of real data, so that we can see what you're actually storing for values. -
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
Let's keep the discussion in here, for the benefit of the community. As I said before, please post your database schema, so that we can tell you if it is properly modeled to allow for JOINs and such, and also for reference. Run this query for each of your tables and post back with results: SHOW CREATE TABLE `data`;Replace data with each of your table names. -
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
But if you're reading 300+ records from the database, you have a huge bottleneck. Pagination is not just limited to actual "pages", like in a blog - they are also very relevant in API's, which is basically what you have here. You need to limit how much data you are pulling from the database and sending through the server. People are never going to need to see their entire calendars worth of data on one go, so pulling all of that data is just wasting resources. How it works is pretty much the same as how it works in any other case. You'd pull, say, 20 records from the database, and then some meta data on total number of records, which page you're on, total pages, etc. Then your AJAX would just pass in a page number to get the next set of data. But, those two queries are literally identical in every way; unless I'm just really blind. It would help if you posted your database schema. If you have to do a SELECT inside of a loop, then your data is not modeled correctly. -
PHP Application Performance (Smart Caching) Advise
scootstah replied to vpetkovic's topic in Application Design
So, that's your first and biggest problem right there. You shouldn't be loading every single record from the database; you need to use pagination. You load X many initially, X being whatever is a good number for user experience, and then load more as needed. Secondly, when caching dynamic data the common thing to do is to delete the cache when changes are made. If there are no changes, the cache can exist for a very long time since you're just reading it. When a change is made you just delete the cache, and re-create the cache the next time it is read. If changes are very frequent then you might have to tune this a little more. In your data.php, you have the same query running twice. Why? $query_data_members = "SELECT DISTINCT dt_id, dt_date, dt_data, dt_bodypart, dt_wktype, dt_wkurl, COUNT(*) as Total FROM data WHERE dt_username_member = '$username' GROUP BY dt_date ORDER BY dt_date"; $query_data_clients = "SELECT DISTINCT dt_id, dt_date, dt_data, dt_bodypart, dt_wktype, dt_wkurl, COUNT(*) as Total FROM data WHERE dt_username_member = '$username' GROUP BY dt_date ORDER BY dt_date";You also have SELECT queries within loops. BAD! Use proper JOINs instead and keep queries out of loops. This is your second biggest problem. -
I'm just saying not to worry all that much if your HTML is perfectly valid. Obviously if you're missing closing tags, aren't nesting properly, missing closing attribute quotes, etc then those are problems you should fix. The browser probably won't care, but it's still bad. A modern IDE will alert you to most of the big offenders.
-
No, this one:
-
curl isn't responding the same on different hosts
scootstah replied to BurtLo's topic in PHP Coding Help
What does curl_getinfo() give you? -
So, $_SERVER['REQUEST_METHOD'] is GET when we would expect it to be POST. Perhaps mac_gyver is on to something. Can you try the code in my reply before this one, and then post the full log after one form submit?
-
If the HTML is loaded from PHP then it should not matter. But, you can try saving the HTML file and then uploading it to the validator. But, that is kind of an old school thing - nobody really cares about validated HTML anymore. Browsers are smart enough to figure out minor problems most of the time.
-
Are you using Apache? Check the error log. You didn't specify what kind of hosting you have, but if you're using a VPS or similar, the default log (on a Debian-based machine) is located in /var/log/apache2/error.log. The error log may be in another location, as specified in the virtual host configuration for that site.
-
So what is your question, and what problems are you having?
-
mac_gyver, that doesn't explain why a partial URL works but a full one does not. Surely if it was submitting twice, that would not work either? We should be able to test that theory though, by logging to a file. <?php $pathToLog = 'request.log'; $log = '[' . date('Y-m-d H:i:s', time()) . '] '; $log .= "Dumping POST:\n" . var_export($_POST) . "\n-------------\n"; $log .= "Dumping SERVER:\n" . var_export($_SERVER) . "\n-------------\n-------------\n"; file_put_contents($pathToLog, $log, FILE_APPEND);Adjust $pathToLog to a writable location.
-
Additionally add this to your new blank PHP file: var_dump($_SERVER);, just for good measure. Maybe there is something useful in there.
-
I tried the code you sent me and it works with no issue. Therefore, the problem must be either server configuration, or something elsewhere in your script. Is /Ads/placeAd.php a standalone file, or does it get include'd into some other script? I think it must be standalone right, since you're calling it directly from the form? Some things to try: - Create a new, blank standalone PHP file and change your form action to point to it. The only thing you will have in this file is: <?php var_dump($_POST); ?> Verify that $_POST is still empty. - Download Advanced Rest Client extension for Chrome to be able to send a POST request to your server without all of the other HTML/JS stuff running. Alternatively, you can use a CURL request from a command line. This should work: curl -X "POST" -d "Line1=http://www.mariposa.com/" http://url-to-php-file-here- Simplify code wherever possible to try to make something work. For example, remove all other form fields and just have Line1. If you do the test above you can skip this step, however if the test above works then go ahead with this test and see at what point you can get something to work. - Try to log the raw POST request that your webserver sees. If you're using apache there are some modules you can download to do this. The goal here is to see if your webserver is seeing the POST request properly, or if something weird is happening there. - Try (temporarily) replacing your php.ini with a fresh, default one. You can obtain one here. You can either use master or select your version of PHP from the tags. Assuming all the above tests fail, and your webserver sees the request properly, then somewhere between the webserver getting the request and PHP getting the request something is going wrong.
-
Ha, that's pretty whack indeed. I am pretty intrigued at this point. Is there any way that you can share enough of your application so that I can try to re-create the problem on my end? I would only need the page your form is on, with any relevant Javascript, and the script to process your form. You can private message it to me if you don't want to post it publicly on the forum. I'm sort of learning towards a problem with server configuration at the moment, although I'm not sure what. Also something I just thought of - you don't have any sort of code that filters/sanitizes superglobals before they get to where you're processing the form, right?
-
So you're saying that if you literally type "ttp://www.mariposa.com" it works, but "http://www.mariposa.com" doesn't? That's crazy... I'm out of ideas for the moment. Normally, from my experience, when the $_POST is empty it is usually because you exceeded the max POST size setting. But, you have not, in this case. I noticed that you are using enctype="multipart/form-data", but you aren't uploading any files. Why is that? Just for giggles, try removing that attribute from your form completely and see what happens.
-
Huh, that's pretty dang weird. I noticed that you have errors turned off in your php.ini. Can you add this to the top of your script that processes the form? ini_set('display_errors', 'On'); error_reporting(-1);Please post back any errors that you receive.