Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. I didn't recommend anything. I made an 'either' 'or' statement about the possible solutions to cover anything you might be doing since we don't have information from you about what it is you are doing.
  2. late static bindings is a feature of php5.3, therefore you need a server running php5.3.
  3. If this is shared web hosting, you are not gong to be able to install your own version of php as that requires administrative access to the server. You can however select which version of php your account/site uses if that version of php is already installed. It would just be a matter of selecting the php version by what ever method your web host has setup. That your web host would not provide instructions or has not posted them in his FAQ section, suggests that either he does not know how or that the php version you asked about is not installed. Some common ways are by a selection in your hosting control panel or by putting a configuration setting into a .htaccess file. If this is a shared server (i.e. VPS), then you should be able to install any version you want.
  4. You would need to open a socket connection that listens on a specific port number so that your php script actually handles the upload. See the script and the discussion at the following link for how you might do that - http://www.phpfreaks.com/forums/index.php/topic,284122.0.html What reason do you need this information for?
  5. Umm. You are the only person here who would have the ability to investigate that possibility on your server. You can set php setting in a .htaccess file when php is running as an Apache Module. You can set php settings in a local php.ini (sometimes it is named something else) if php is running as a CGI application. Check with your web host for the exact method on your server.
  6. 1 means one byte. It should actually indicate an 'on' value or a reasonably larger numeric value (i.e. 4096.) A) It should not be turned on at all (it just wastes memory and processing time), and B) It is probably what is causing your download to operate slowly and is also probably causing your web pages to be output slowly. Turn output_buffering off. The only way I was able to reproduce a 1 value was by setting it to a 1 or by using a php_flag setting in a .htaccess file (it is actually a php_value setting in a .htaccess file.)
  7. Creating code that does what you want, when and where you want it to be, is not a matter of reading somewhere about something, it is a matter of making your code do what you want and when your code does not do what you want it is a matter of troubleshooting what it is doing. Did you look at and read the code that is responsible for producing the output in question. The for(){} loop that is producing the menu contains the entire code for the <select>...</select> menu inside of it, so of course you will get a complete menu for each pass through the for(){} loop. Wouldn't the solution be to output just the <option>...</option> choices inside of the for(){} loop?
  8. What does a phpinfo() statement show for the output_buffering setting?
  9. None of that is necessary. If you A) read the session handling section of the php.net documentation - http://us2.php.net/manual/en/book.session.php (i.e. you are trying to incorporate sessions into your script, you must read the documentation for what you are doing to be affective at doing it) you will B) find that there is a session.cookie_domain setting that will allow the session cookie to match all sub-domains/host-names of your domain.
  10. If there are no actual characters in the file before the <?php tag, then your file has been saved as a UTF-8 encoded file and the BOM (search if you don't know what that means) characters that your editor placed at that start of the file are the output that is preventing the header from working. Save your file either as an ANSI encoded file or if you must save it as a UTF-8 encoded file, save it without the BOM. If your editor does not have the option of saving a file using either of the suggested methods, you need to use a better programming editor.
  11. You don't define them. The browser takes the name="..." attribute and produces the name.x and name.y values which php then converts to name_x and name_y. Your form method='post' and submit image button has name="submit", so you would detect if the submit button was clicked by checking if either one $_POST['submit_x'] or $_POST['submit_y'] is set. Alternate methods of detecting if your form has been submitted would include using a hidden field or adding a get parameter on the end of the URL in the action="..." attribute.
  12. Your form is using images as submit buttons. See the following link on how to get php to detect or process the resulting x and y coordinates where the image was clicked (works for all browsers) - http://us3.php.net/manual/en/faq.html.php#faq.html.form-image
  13. It would appear to be the value from the form that corresponds to the 'changemx' field. I don't think removing it would solve anything. You would need to find out why it is not being set from the form field. Your code needs to - A) validate the data being put into the query so that you only execute the query when all expected data is present, B) escape any string data that is being put into the query to prevent sql injection, C) cast any integer data as an INT that is being put into the query to prevent sql injection, and D) put single-quotes around any string data.
  14. Someone previously suggested in one of your threads that you echo $query so that you can see exactly what it contains.
  15. INSERT queries don't have WHERE clauses. Before you can create an application that uses queries, you must have an understanding of what each type of query is. The tutorial at the following link shows basic INSERT, SELECT, UPDATE, and DELETE queries - http://w3schools.com/php/php_mysql_intro.asp
  16. How are you invoking the current script? Sounds like you have 'forked' a background process and the script runs continuously in a loop? You could use a cron job/scheduled task to invoke the script once a minute (one minute is often the smallest cron period you can choose.) This would eliminate extra code and you could just process any waiting records, which would prevent any records from being 'stuck' in the queue. You might also consider using a single script. The script that receives the original data could just process it as it is received. If the script that is processing the original data is running on the same server as the script you have shown in this thread, a single script would actually reduce the amount of processing time used and the single script would have a greater through-put than the current arrangement.
  17. Is there some reason why you are not using any of the mysql date and time functions directly in your query to do this? In fact, what are you attempting to accomplish? It is almost always simpler and faster (php is a relatively slow parsed, tokenized, and interpreted language compared to the compiled code of a database engine) to let the database engine retrieve the rows you are interested in, in the order that you want them, and with each piece of data formatted the way you want it.
  18. match is a reserved mysql keyword and an unfortunate name to pick for a mysql table. I recommend you rename it to something else. You should also post the errors you get when you run your code.
  19. The following is the equivalent (untested, use at your own risk) code to what you posted above - <?php // the following query does not seem to need an ORDER BY term and assuming that the processed column is an INT remove the single quotes around the zero value. $get_data = mysql_query("SELECT * FROM raw_data WHERE processed = 0") or trigger_error('RawDataQueryFailed: ' . mysql_error()); while($data = mysql_fetch_assoc($get_data)){ // continously fetch data // use the $data variable directly // $row_id = $data['id']; $tweet = json_decode($data['tweets']); if ($tweet->user->screen_name != '' && $tweet->text != ''){ $date = time(); // use the time() function. Since this value is used in more than one query, fix the value at this point $user = mysql_real_escape_string($tweet->user->screen_name); $twt = mysql_real_escape_string($tweet->text); $prof_img = mysql_real_escape_string($tweet->user->profile_image_url); echo 'Username: '.$tweet->user->screen_name.'<br>'; echo 'Tweet: '.$tweet->text.'<br>'; //echo 'Date: '.$date.'<br>'; // link is not set in this code // echo 'Link: '.$link.'<br>'; //echo '<img src="'.$tweet->user->profile_image_url.'">'; // this actaully causes the browser to fetch the image echo '<hr>'; // insert data into db // link is not being set in the posted code so every access of it slows php down since it must still handle the error $link = ''; if ($link != 'not found'){ // Check if user exists in db // $query = "INSERT INTO users (username, profile_img) VALUES ('$user', '$prof_img') ON DUPLICATE KEY UPDATE profile_img = '$prof_img', id=LAST_INSERT_ID(id)"; mysql_query($query); // the $u_id variable was not used in this code // $u_id = mysql_insert_id(); // Record link // $query = "INSERT INTO link (url, count, long_url, first_seen, last_seen) VALUES ('$link', 1, '$long_url', $date, $date) ON DUPLICATE KEY UPDATE count = (count + 1), last_seen = $date, id=LAST_INSERT_ID(id)"; mysql_query($query); $link_id = mysql_insert_id(); // get the last id from the insert or from the update // Insert Tweet // $sql = mysql_query("INSERT INTO tweets (tweet, date, link_id, username) VALUES ('$twt', $date, $link_id, '$user')"); $tweet_id = mysql_insert_id(); // Create relationship $sql = mysql_query("INSERT INTO relationships (username, tweet_id, link_id) VALUES ('$user', $tweet_id, $link_id)"); } } mysql_query("DELETE FROM raw_data WHERE id = {$data['id']}"); } // end while loop ?> You have some undefined/unset variables in the code that probably account for any symptoms like it not inserting into the links row... that you would need to troubleshoot (i.e. we don't know where you intended to get the missing data from.) I kept the $date variable (changed it to use the faster time() function since it is used in more than one query.) I also made an assumption about the auto-increment column name 'id', in order to satisfy the LAST_INSERT_ID() function in the query (needed so that the UPDATE query will also set the mysql_insert_id() value.)
  20. Edit: The reason the code just posted is slower is because it actually executes more queries, not less. Actually, your code was already executing the extra query that I saw. There are several things you can do that would speed up the code. 1) Change mysql_fetch_array() to mysql_fetch_assoc() 2) Don't use $date = date('U'); in your php code. Use one of the mysql functions directly in your query to get the date/time in the format you want. If you are truly using a Unix Timestamp, see the mysql UNIX_TIMESTAMP() function. 3) Don't echo data to the screen or echo a minimum of it. 4) The // Check if user exists in db // block of code can be replaced by a single INSERT ... ON DUPLICATE KEY UPDATE query. The username column should be a unique index. 5) The // Record link // block of code can also be replaced by a single INSERT ... ON DUPLICATE KEY UPDATE query. The url column should be a unique index. 6) Remove any @ in your code. They actually cause extra code to be executed even if there are no errors and you should simply have display_errors set to OFF anyway so there is no need to put any @ in any code. 7) Is your raw_date id column a primary key? Here is the INSERT syntax showing the ON DUPLICATE KEY UPDATE syntax -
  21. You must actually echo values out from php code if you want them to be output to the browser. You should also use full opening php tags <?php
  22. That statement provides us with zero useful information about what symptoms, errors, or problem you saw in front of you when you tried this on your system. We only see the information you provide in your post and since we don't have access to your server, you are the only one here who can actually run your code in your environment and tell someone not standing right next to you what happened.
  23. That code is way out of date and should have been updated or removed from distribution long ago. It will likely have other issues running on current versions of php. For your present problem, just change all the occurrences of $this to a different name.
  24. Actually, YYYY-MM-DD is not a US format. It is a left-to-right, most significant (year) to least significant (day), format that allows dates to be compared and sorted correctly. There are several methods that you can use to changed the format from what is being entered into the expected format. Two of the fastest are - 1) After you validate the entered date, use explode to break the date into its separate fields, then put the pieces back together in the correct format, 2) After you validate the entered date, use the mysql STR_TO_DATE() function directly in your query to produce a DATE value from the entered value. date_default_timezone_set() only sets the time zone that the php functions like date(), mktime(), strtotime()... use. It has no effect on what your code does with the data it receives.
  25. Have you echoed the query in $sql; so that you can see exactly what it is?
×
×
  • 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.