-
Posts
1,807 -
Joined
-
Last visited
Posts posted by hitman6003
-
-
um - can i tell php in any way to use the filename of the script that has gone: require("ME???");???
not sure what you're asking.
-
If you have control over your mysql server, turn on query caching....when the exact same query is issued it will pull the result from the cache and not actually query the database. When the table (or tables) that are selected from are updated in anyway (INSERT, UPDATE, DELETE), it will invalidate the cache and requery...
If that isn't an option, then your best bet is to write a text file with the result set. Then use the file's modified time to gauge when to requery.
Cookies are user specific...unless that is what you want.
-
When I ask the login.php to display the script name, which URL will it display/use?
Why don't you try it and find out...
echo __FILE__;
-
$_SERVER['DOCUMENT_ROOT']
-
Sorry, got distracted and gave you an incomplete example...
<?php $data = array_map(create_function('$a', 'return "option_" . $a;'), range(1, 20)); $data = shuffle($data); echo "Group One:<br />"; for ($i = 0; $i < 10; $i++_ echo '<input type="checkbox" value="' . $data[$i] . '"> ' . $data[$i] . '<br />'; } echo "Group Two:<br />"; for ($i = 10; $i < 20; $i++_ echo '<input type="checkbox" value="' . $data[$i] . '"> ' . $data[$i] . '<br />'; }
-
put them into an array, then use the array_shuffle function
http://www.php.net/array_shuffle
$data = array_map(create_function('$a', 'return "option_" . $a;'), range(1, 20)); foreach ($data as $option) { echo '<input type="checkbox" value="' . $option . '"> ' . $option . '<br />'; }
-
-
pass an attachment content-disposition header...
header('Content-Disposition: attachment; filename="downloaded.pdf"');
-
however if you call the function like
object::b();
you will need to define the function as follows
function a() { echo "a"; } function b() { self::a(); }
The function should (would have to?) be declared static as well.
-
Unless the filename actually contains the "%20" characters, replace them with a space ("%20" == " ").
-
MySQL is a multi-threaded application...so it will automatically spawn a thread for each connection.
Have you actually timed the different parts to determine where the bottle necks are? I saw you noted one in your code, but have to used microtime to actually time each of the queries and the "specialMath" function?
Also, buffer the deletes so that you can do only one query for all of them...
<?php //Get all records from queue, oldest first $start = microtime(true); $sql = "SELECT id, latitude, longitude, date_inserted FROM queue ORDER BY date_inserted ASC"; $result = mysql_query($sql) or die(mysql_error()); echo "The initial query took " . (microtime(true) - $start) . " seconds\n"; echo "There are " . mysql_num_rows($result) . " rows in the result set\n"; $delete_ids = array(); while ($row = mysql_fetch_array($result)) { $start = microtime(true); $address_object = spacialMath($row[1], $row[2]); echo "It took " . (microtime(true) - $start) . " seconds for spacialMath on row with id " . $row[0] . "\n"; $start = microtime(true); $sql = "UPDATE spacial_data SET address = '" . $address_object->address . "', polygon_min = " . $address_object->polygon_min . ", polygon_max = " . $address_object->polygon_max . " WHERE id = " . $row[0]; // use an unbuffered query here...no need to return a result mysql_unbuffered_query($sql) or die(mysql_error()); echo "It took " . (microtime(true) - $start) . " seconds to update the row\n"; $delete_ids[] = $row[0]; } $sql = "DELETE FROM queue WHERE id IN(" . implode(", ", $delete_ids) . ")"; mysql_unbuffered_query($sql) or die(mysql_error());
-
pretty sure that unless that "script" is being called many thousands of times per second, it's not causing a problem.
On my Core 2 Duo Laptop running Fedora 8, I ran the your code above one million times in 14.01 seconds, during that time, it consumed 48% CPU...or about 96% of one core.
At that rate, your code would have to be called 71428 times per second to consume 100% of CPU resources.
I think that either the problem lies somewhere else, or you need a new host who doesn't whine when you use more than 2% cpu.
<?php $iterations = 1000000; $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { // Throw out a random image $pic = array( "front_pic_1.jpg"=>"Front_Pic_1", "front_pic_2.jpg"=>"Front_Pic_2", "front_pic_3.jpg"=>"Front_Pic_3", "front_pic_4.jpg"=>"Front_Pic_4", "front_pic_5.jpg"=>"Front_Pic_5" ); print_r(array_rand($pic,1)); } echo "\n\nTotal time for " . $iterations . " iterations: " . (microtime(true) - $start) . " seconds"; ?>
-
Have you tried reducing the number of times that the script is run?
Setup for the script takes some time (database connection and query for example), and perhaps eliminating that overhead every 60 seconds will enable the server to devote more cycles to actually processing the data.
Currently, every 60 seconds the script does...
check if self is running, if so, kill self connect to db query db loop through 250 rows (15000 rows per hour / 60 minutes) doing functions exit
Perhaps changing that to 7500 rows every 30 minutes will help.
Try to run the script once every 15 - 30 minutes (on a test data set, not live) and see if it makes a difference.
Also, what "calculations" are you doing on the row(s) that it's taking longer than 60 seconds for ~ 250 rows?
-
SUM is an aggregate function, you can't use it when selecting other columns that are not aggregated.
-
They are three similar, but different, XML-over-HTTP based protocols that allow two servers to communicate.
I recommend google to learn more...
I like Zend Framework's classes for creating and consuming each service...
-
There is no form element with the name "submitform", therefor it will not be in the $_POST array.
Use print_r to see what is in the $_POST array...
echo '<pre>' . print_r($_POST, true);
A better test to determine if the form was submitted would be to test if your text input contains a value...
if ($_POST['query'] != "") { echo "The form was submitted."; }
-
I was sure that all function scope was global.
No, a function's scope is limited to where it was declared at. If it is declared in the global namespace, then, yes, it is global. However, if it is declared in a class, it it not global, but local to the class.
If cakePHP is anything like Zend, and assuming you are using your posted code in a view script, then it is probably evaluated code inside the view class...try calling the function using the $this-> nomenclature....
<?php function a() { echo "a"; } function b() { $this->a(); } ?>
The worst that will happen is nothing.
-
Use a where clause...
SELECT ... WHERE user = 'test'
-
XML-RPC / REST / SOAP service(s)...
-
You have to get the result of your query out of the "Resource" returned by the query...
$INK = mysql_query("SELECT SUM(InkCosts) FROM Stats WHERE Month='$MONTH' AND Year='$YEAR'"); echo mysql_result($INK, 0);
-
First off, that is the most headache inducing description I've ever read.
Secondly, does $username change (it's pulled from a mysql table, determined from a POSTed value, etc)? If not, why are you putting it in a variable to begin with? I can only assume it is dynamic, in which case, it has to be a variable.
Memory wise, yes, it will consume a few bytes more, but nothing worth even noting.
-
There is an max_allowed_packet size (default 1MB)
I think that only applies to MySQL.
-
What about on the entire result set?
echo '<pre>' . print_r($row, true);
-
[SOLVED] for loop problem, I think this is a simple fix one! (I hope)
in PHP Coding Help
Posted
Put the loop outside of inserting it into the array for output.