prince198 Posted July 11, 2008 Share Posted July 11, 2008 hi all after hard battle with days in php and thank for all that they help me here . i finelly create functions with my sql that let me count number days between 2 days but in week and of course i can jump on years without bugs but now i find that is take 10 secondes of time excecution in php. i tried smarty for cache systeme but no result my function is : <?php function count_date($SAR) { $PARAM_hote='localhost'; // le chemin vers le serveur $PARAM_name_bd='database'; // le nom de votre base de données $PARAM_user='root'; // nom d'utilisateur pour se connecter $PARAM_pass=''; // mot de passe de l'utilisateur pour se connecter try { $connexion = new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_name_bd, $PARAM_user, $PARAM_mot_passe); } catch(Exception $e) { echo 'Erreur : '.$e->getMessage().'<br />'; echo 'N° : '.$e->getCode(); } $sql=" select SAR, start_day, end_day from table"; $requete=$connexion-> query($sql); $result = $requete -> fetchALL(); $To_days_start_final=0; $first_week = dayOfTheWeek(01, 2008, 0, "U"); $last_week = dayOfTheWeek(52, 2008, "+5", "U"); $first_day__week=date("Y-m-d", $first_week ); $last_day__week=date("Y-m-d",$last_week); $To_days_first_day__week=to_days($first_day__week); $To_days_last_day__week=to_days(last_day__week); $nbrdays1 []= 0; foreach ($result as $row) { $Brigade= $row['SAR']; $start_day = $row[start_day]; $end_day = $row[end_day]; /**********************************************************************************/ if ($start_day < $first_day__week ) { $start_day_final=$first_day__week ; } else { $start_day_final=$start_day_final; } /**********************************************************************************/ $To_days_start=to_days($start_day_final); $To_days_end=to_days($end_day); $Get_week =date('W',strtotime("$start_day_final")); $week= trim($Get_week , 0); $day_week=date('N',strtotime("$start_day_final")); /***********************************************************************************/ if( $To_days_end > $To_days_last_day__week) { $To_days_end_final = $To_days_last_day__week; } else { $To_days_end_final = $To_days_end; } if (ereg($SAR,$Brigade)) for( $day= $To_days_start; $jour <=$To_days_end_final; $day++ ) { if( $day_week >= 1 AND $day_week < 7 ) $nbrdays1[$week]++; $day_week++; if( $day_week > 7 ) { $week++; $day_week = 1; } } } ksort($nbrdays1); print_r($nbrdays1); } for functions that u find here like to_days and first week is after helping of some friend here there is adresse of topic http://www.phpfreaks.com/forums/index.php/topic,205871.msg933951.html#msg933951 http://www.phpfreaks.com/forums/index.php/topic,206028.msg934850.html#msg934850 my script work now and i have result for exemple if i have in my table start_day: 2008-01-01 end day ;2008-01-09 will display week 1: 5 days( because week 1 strat in 31 december 2007) week 2: 3 days but now in my tbale i have 2000 lines ans my script need 10 secondes to execute . so imagine if i have 10000 lines :-\ u know how i can reduce the time of excution and optimize it thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/ Share on other sites More sharing options...
rmbarnes82 Posted July 11, 2008 Share Posted July 11, 2008 Hi, Are you really looping through all 2000 rows in the database table in that script? If so thats always going to be slow. Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587484 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 i can have even 20000 rows so how i can reduce time excecution cause with 2000 rows take 10 seconds Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587497 Share on other sites More sharing options...
ILYAS415 Posted July 11, 2008 Share Posted July 11, 2008 r u trying to reduce time of page execution or mysql execution? Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587503 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 i think both because as you see i save result in array in my sql i take only start_day and end day and in php i transform in function like to_days in mysql and i give all conditions to count niumber day by week in year so i don't have really long time in mysql but because i have all this conditions in php take this 10 second and i'm afraid when i have 2000000 rows so i have to wait 2 min may be more Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587508 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 first did you unterstand my script or not? Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587512 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 nobodt have solution with OOP Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587530 Share on other sites More sharing options...
Guest Xanza Posted July 11, 2008 Share Posted July 11, 2008 Nothing you can really do to decrease the time of the mysql execution... But if you would like to decrease your overall page load time, look into gzipping your scripts. Keep in mind, your server has to support, and have it enabled. If you want to look into it more, make sure your web host supports it, and enable it this way: http://elliottback.com/wp/archives/2006/01/12/http-gzip-compression-in-php/ Hope this helped. Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587548 Share on other sites More sharing options...
rmbarnes82 Posted July 11, 2008 Share Posted July 11, 2008 Hi, What are you trying to accomplish? Will a user view this page or is it just some kind of automated maintenance script? If it's a maintenance script then viewing via the web is the wrong way to go about this. Robin Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587555 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 it's user that will see the result . so that why i need to decrease time execution because take long time Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587557 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 i don't finf how to upload compression-in-php/ :-\ Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587561 Share on other sites More sharing options...
Guest Xanza Posted July 11, 2008 Share Posted July 11, 2008 First make sure your host supports gzip compression, secondly: In PHP, there are two easy ways to do this. The first is to add the following to your .htaccess file and let Apache do the rest: php_flag zlib.output_compression on php_value zlib.output_compression_level 2 The second is to add the following to the top of your php script file: ob_start(”ob_gzhandler”); Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587567 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 ok i will try but u think that there is not solution to change some line in myscript to be optimized? Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587573 Share on other sites More sharing options...
Guest Xanza Posted July 11, 2008 Share Posted July 11, 2008 ....dude, this is the solution for something to be changed for your script to be optimized... But like I said, for the sql tables, their probably isn't anything you can do... Except some house-cleaning. Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587579 Share on other sites More sharing options...
prince198 Posted July 11, 2008 Author Share Posted July 11, 2008 i hope your solution will help me cause ftaer few month i will have 100000 rows :-\ thank for your help Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587585 Share on other sites More sharing options...
PFMaBiSmAd Posted July 11, 2008 Share Posted July 11, 2008 The point of a database is to retrieve just the data you are interested in. You don't query for all the data and then use some slow parsed/tokenized/interpreted php code to scan through it to find or calculate the information you want. You need to form your sql query so that it contains sql functions that directly select or calculate what you want and a WHERE clause that only selects the data you want. If you don't already know how to do this, you will need to get a basic mysql book to read or find and study some online tutorials. If you describe specifically what your code is supposed to be doing (what the starting data looks like and what the results should be) and what your table definition is (it is possible that your table design is making the problem harder than necessary), someone can provide assistance. Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587634 Share on other sites More sharing options...
rmbarnes82 Posted July 11, 2008 Share Posted July 11, 2008 Hi, PFMaBiSmAd is right. Gziping your script / output is basically pissing in the wind here and won't help you. Your program as is will time out with 100,000 rows in the database. I think you need to provide a detailed account of what you want your script to achieve, as your whole approach seems wrong. Robin Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587636 Share on other sites More sharing options...
Guest Xanza Posted July 11, 2008 Share Posted July 11, 2008 PFMaBiSmAd is right. Gziping your script / output is basically pissing in the wind here and won't help you. Read my posts, I told him that it would not help his SQL... Only basic website load times... damn. Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-587725 Share on other sites More sharing options...
rmbarnes82 Posted July 12, 2008 Share Posted July 12, 2008 Read my posts, I told him that it would not help his SQL... Only basic website load times... damn. Wasn't meaning to attack your post, its just I really wanted to get across to OP that what he's doing is wrong on a fundamental level, so he needs to completely rethink his whole approach, not look for optimizations to what he currently has. Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-588101 Share on other sites More sharing options...
prince198 Posted July 14, 2008 Author Share Posted July 14, 2008 hi evrybody and thank you for all response i will explain my script: we start from database like this start_day | end_day | work 2008-01-01| 2008-02-02| morning 2007-12-25 | 2008-01-15 | evening and now i have my script must to have result for example in year 2008 for person who work in evenig how many days he work but in week so year 2008 start in mondy 31 december if we want respect ISO... so this person work in week 1(from 31december 2007 to 52008-01-05) 6 days week 2 :6 days week 3 : 2 days of course i don't calculate sunday and week start in monday so i hope now u unterstand workinf pof script and my database Quote Link to comment https://forums.phpfreaks.com/topic/114255-reduce-execution-time-in-my-script-php/#findComment-589699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.