Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. I've experienced plenty of problems like this. You can fix them with patience and hard work. First, determine a method of logging from each part of your code. Eg, the javascript can log what it is doing by editing the page and giving status updates. The php scripts can log to a file, or to output (if their output will be displayed to you). If the php script is responding to an ajax call, it will probably have to log to file. Then place debugging output throughout your program. This stage is simple. All you do is find which debugging output appears and which doesnt. Then you add more debugging statements at the point at which output stops. Eg. print "<b>Entering db call 3</b><br>"; ... print "<b>Passing data to foo()</b><br>"; If you see "entering db call 3" but you don't see "passing data to foo()", then you know where your script is hanging. So you add more debugging calls between those two statements. Eventually you find the exact statement where the script hangs. Then you have one line of code to debug, rather than thousands
  2. Can you provide more detail? Do you want to execute several queries in sequence, or do you want to combine data from several queries into one result set?
  3. The relevant code is in Zend/zend_operator.c, in the function increment_function(). Assuming you're using a long for the semaphore, the code from php 5.1.6 looks like this: if (op1->value.lval == LONG_MAX) { /* switch to double */ double d = (double)op1->value.lval; ZVAL_DOUBLE(op1, d+1); } else { op1->value.lval++; }
  4. I just cut sorting time down to 8 seconds for my 200k length arrays, vs 4.7 seconds for php's native arrays.  That's less than double, which is pretty good I think.  The cut from 20 seconds to 8 seconds was achieved by allocating two zval arrays at the start of the sort, and re-using them for each comparison.  The 12 seconds removed was previously spent allocating and de-allocating all those values! So the summary is: C arrays vs PHP native arrays 16.3MB vs 85.8MB (80% reduction in memory usage) 8s vs 4.7s (70% increase in sorting time) Not bad eh?  If only I could cut the sorting down a bit more.
  5. Yes, I've used that with success. I'm not sure if the html_entity_decode() in the example I linked to is actually necessary. I've found urldecode() alone to work for me. After that, you should use mysql_real_escape_string() if that data is going into a mysql query. But if it's going to be displayed in an html page, you should use htmlentities(). $article_name = urldecode($_REQUEST['article_name']); $article_name_for_db = mysql_real_escape_string($article_name); $query = "SELECT * FROM table WHERE article_name = '$article_name_for_db'"; $article_name_for_html = htmlentities($article_name); print "<h1>$article_name_for_html</h1>";
  6. htmlentities() is for escaping text for display in an HTML document. For processiong input variables, take a look at the example at the top here. After you've removed html escaping on your input, the next step is to make the string safe with mysql_real_escape_string(). Then your string is safe for use in mysql. Note that it still MUST be enclosed in quotes inside the mysql statement, or else it's not safe. The only other thing I notice right away is your inconsistent syntax for include(). It's also better to use include_once() or require_once(), as that will save you trouble with recursive includes.
  7. Let's say I've allocated a zval as follows zval *zv; MAKE_STD_ZVAL(zv); If I want to free this zval properly, how should I do it? Is it enough to call zval_dtor()? FREE_ZVAL()? I have seen some extensions that call BOTH of these. Second question: If zv is an array, do I need to do something special to ensure that the array elements are also freed?
  8. If this isn't solved (As its marked), please post your modified code, then we can take a look and tell you why you get the error
  9. If you have basic php knowledge, you can find an appropriate place (or places) to add code that simulates register_globals. The code will look something like this: <?php foreach($_ENV AS $key => $value) { ${$key} = $value; } foreach($_GET AS $key => $value) { ${$key} = $value; } foreach($_POST AS $key => $value) { ${$key} = $value; } foreach($_COOKIE AS $key => $value) { ${$key} = $value; } foreach($_SERVER AS $key => $value) { ${$key} = $value; }?> Or you could post in freelancing and ask someone to fix the script for you. The first option though would be to get your script provider to fix it. Requiring register_globals is frowned upon by modern php programmers.
  10. This extension is now functional, and has some primitive sorting capabilities.  Sorting is quite slow, using a php callback.  But data is nicely packed.  Storing an array of 20k rows, each looking like this: [code=php:0]  c_array_push($c_arr, array(     0 => 'pickles',     1 => 1,     2 => 2.5 + rand(0,10),     3 => 3.5,     4 => 'bananas',   ));[/code] takes 1.9MB, compared to php's 8.6MB for the exact same array. Creation of the array takes 0.08 seconds for c_array, compared to 0.07 seconds for a native php array.  Note that this time includes creating half the array using named elements instead of integer indices. Sorting of the array by element 2 takes 1.7 seconds for c_array, compared to 0.41 seconds for native php array.  This could use improvement. Currently I am sorting with C's qsort(), generating a php data structure from the c_array and passing it back to a php callback to do the comparison.  That's overhead that the native php sort doesn't have.  Perhaps some pre-defined native C comparison callbacks could speed this up. More data: 200k array entries, same structure as above. c_array creation: 0.73 seconds php array creation: 0.74 seconds c_array sort: 20.89 seconds php array sort: 4.72 seconds c_array memory: 16.3MB php array memory: 85.8MB That's an 80% reduction in memory use.  The reduction for arrays of pure integers and other small data structures will be even greater.
  11. I don't this is a core hacking issue. It's more likely to do with the parameters you're passing to imagecopymerge()
  12. A small clarification - mod_rewrite is the mechanism for rewriting and redirecting urls, which is often done in .htaccess. Disabling register_globals isn't related to mod_rewrite, although it can be done in the same file.
  13. register_globals just makes certain variables global by default. You can always make more variables global yourself in the script. <?php function build_where_clause($_POST, $fields_labels_ar, $table_name) //Start showing other counts .... if ($results_type = "search"){ $order_one = str_replace('`','',$quote.$field_name_temp.$quote); $query = "SELECT ".$table_name.'.'.$order_one.", COUNT(".$table_name.'.'.$order_one.") AS Total FROM ".$table_name." LEFT JOIN equivalences ON ".$table_name.'.'.$order_one." = equivalences.equiv GROUP BY ".$table_name.'.'.$order_one." ORDER BY ".$table_name.'.'.$order_one. " ASC LIMIT 0, 30 "; $result = mysql_query($query) or die(mysql_error()); // Print out the contents of each row into a table, and store them too $results = array(); while($row = mysql_fetch_array($result)){ echo '........... $results[] = $row; } return array( 'where_clause' => $where_clause, 'results' => $results, ); } // end function build_where_clause this the another function from where i want to call the $row results from function build_where_clause() function getSalesByYear($_POST, $fields_labels_ar, $table_name) { //Initialize <categories> element $strCat = "<categories>"; //Initialize datasets $strAmtDS = "<dataset seriesname='Revenue'>"; $strQtyDS = "<dataset seriesName='Units Sold' parentYAxis='S'>"; // Here is where i want to retrieve the data fetched from $query in the build_where_clause() function: $ret = build_where_clause($row); $where_clause = $ret['where_clause']; $results = $ret['results']; $strCat .= "<category label='" . $row['Total'] . "'/>"; //Generate the link $strLink = urlencode("javaScript:updateCharts(" . $row[$order_one] . ");"); $strAmtDS .= "<set value='" . $row['Total'] . "' link='" . $strLink . "'/>"; $strQtyDS .= "<set value='" . $row['Total'] . "'/>"; //Closing elements $strCat .= "</categories>"; $strAmtDS .= "</dataset>"; $strQtyDS .= "</dataset>"; //Entire XML - concatenation $strXML = $strCat . $strAmtDS . $strQtyDS; return $strXML; }// End function getSalesByYear ?>
  14. Try this: echo "Title:<input type=\"text\" name=\"title\" size=\"50\" value={$row['title']}"><br>";
  15. the mysql_real_escape_string part protects against injection. So yes that function does protect against injection. For question 1, you need to worry only about the data you specify in the query. For example, if you select by name, you must worry about injection in the name, but not in the data returned from the database.
  16. fopen("file", "w") will create a file that doesn't exist. But the directory MUST exist first. You need to check the return value of fopen() to see that it's really opened the file. If fopen() isn't working, there may be a permissions problem.
  17. Formatting is done with the date() function. You can use strtotime() and add 1 week to get the next friday. For example, date('Y-m-d', strtotime('2007-09-01 +1 week')). I'm not sure how that handles DST changes, but it's probably ok.. To find the first friday, you can use strtotime()'s other features like 'next Friday'
  18. You can use conditional statements (if) within somefile.php, based on a variable set by your including script.
  19. Your subject_id is probably empty. That's my first guess.
  20. There are 2 methods you can use: 1. Declare a variable global in BOTH functions. Keep in mind that it will keep its value between calls to the functions. The line "global $var" will do this. 2. Return an array containing all the data you need, instead of a simple variable. Eg. return array( 'where_clause' => $where_clause, 'query_data' => $query_data, );
  21. Probably to make the class re-usable. If you hardcode $_POST into your class, then your class will only work with post forms with those particular variable names. But if you process the data in index.php then pass it to your class, the class is much more flexible. If you have no intention of ever re-using your class elsewhere, then yes you can use $_POST inside it and forget the whole thing You'll probably regret it later, but it's all a learning experience..
  22. There are so many places that script could go wrong.. I recommend you print out ALL the values that might possible influence the decision on whether to use the cached value or do a fresh check. The other thing you might want to do is time some of your functions, and make sure it really is the server check and not anything else that is causing the delay (you could verify this just by commenting out the server check code, if you don't want to go to the effort of timing) A good start would be printing out $dstamp and $currentstamp right before you test them, as well as $forceupdate
  23. Which function do you use before fputs(), and what problem do you have? Are you using fopen()? Can you post your code?
  24. Have you tried printing out the values of all the variables you are testing? Something like this: print "<br>About to test error[username]: {$error['username']}"; if ($error['username']) { print "<br>error[username'] evaluated to true"; # stuff }
×
×
  • 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.