11Tami Posted April 10, 2007 Share Posted April 10, 2007 Hello, regarding microtime etc. I already saw what the manual said and all it says it that it returns the unix timestamp for a particular time. I need to know some opinions on how this could work in some php functions. For instance if I set microtime on a random function, by default does it only show the particular time on page load only? Or is there a way to keep it firing.....?? Please let me know, thank you very much. Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/ Share on other sites More sharing options...
Glyde Posted April 10, 2007 Share Posted April 10, 2007 Microtime really has little use outside of the standard "Execution time" scripts. I can't really tell exactly what you want, so I can't say if it'll be useful for you or not...but when you make it clear I'll try to help. Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226294 Share on other sites More sharing options...
11Tami Posted April 10, 2007 Author Share Posted April 10, 2007 I have just seen microtime used a lot so I need to find out if its something I can use. Just trying to find out more about it. Can you tell me more about the exectution time scripts your talking about and how the microtime in those can help them? Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226309 Share on other sites More sharing options...
Glyde Posted April 10, 2007 Share Posted April 10, 2007 The execution time script is a simple script that display how long it takes for a block of code to execute. This is used frequently in development, but also frequently taken off before the site goes live. This script can easily allow a code developer to trace the source of a slow script down to a single line or maybe a block of code. PHP.net's microtime page has an example: http://us2.php.net/manual/en/function.microtime.php They are the first two examples on the page and they simple show how long it took the script to execute. Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226312 Share on other sites More sharing options...
11Tami Posted April 10, 2007 Author Share Posted April 10, 2007 Thank you I appreciate that explanation. I uploaded them to take a look. They are just saying how long it took the script to execute and nothing else I take it, like you said. Is there any way to get a script to keep executing using microtime? Or does it need a page refresh to keep executing. Please let me know someone, thank you very much. Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226330 Share on other sites More sharing options...
Glyde Posted April 10, 2007 Share Posted April 10, 2007 You can do something like this (PHP 5): <?php $startTime = microtime(true); $timeToRunFor = 1000; $endTime = $startTime + $timeToRunFor; while (microtime(true) < $endTime) { someFunctionToExecute(); } ?> It will run someFunctionToExecute() repeatedly for 1000 microseconds Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226339 Share on other sites More sharing options...
11Tami Posted April 10, 2007 Author Share Posted April 10, 2007 I appreciate that thanks for getting me started with this. Just for fun I put an echo in this part of it.. someFunctionToExecute(echo "test"); But it wouldn't accept php code inside someFunctionToExecute(); Don't I put a function inside the paranthesis? Any idea what I'm doing wrong? Thank you very much. Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226380 Share on other sites More sharing options...
Glyde Posted April 10, 2007 Share Posted April 10, 2007 someFunctionToExecute() is a pointer to a function called someFunctionToExecute. Since this function is undefined, it will generate errors. Try this: <?php function someFunctionToExecute() { echo "test"; } $startTime = microtime(true); $timeToRunFor = 1000; $endTime = $startTime + $timeToRunFor; while (microtime(true) < $endTime) { someFunctionToExecute(); } ?> Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226386 Share on other sites More sharing options...
11Tami Posted April 11, 2007 Author Share Posted April 11, 2007 That makes sense, I'll play around with it, check your pm. Link to comment https://forums.phpfreaks.com/topic/46504-microtime-help-already-looked-in-the-manual/#findComment-226410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.