Solved

php no error but execution stops

Posted on 2009-07-11
7
801 Views
Last Modified: 2012-05-07
I have a program that reads xml files (7 at a time), each xml file is large and contains data of particular dates, i am running a loop in the following order
1) loop for 7 days a week
2) loop for the 7 xml files
3) the xml files are too deeply structured, i have retrieved them in an assoc array. now to go to particular fields , there is a nested loop of 12 x 50 ( it is necessary)

in the beginning of the script, i have :
ini_set('memory_limit', '256M');        
ini_set('max_input_time', 300);        
ini_set('max_execution_time', 3600);  
set_time_limit(3600);
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

After doing this also, my script doesn't execute completely, it stops in between and no error.
can anyone tell me what exactly is the problem, when i see view source , i see that the source is not executed completely, for some reason the script stops
any idea on why this might be happening ??
0
Comment
Question by:Desire2change
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:basic612
ID: 24830069
to tell you in detail we would need to see the code you are running.

to get an idea yourself I would be putting in some echo "I am here" or  echo "Iteration $i" type debugging messages in your code in the looping sections. that way you can track down where execution is failing.

put the line:

    die( "got here");

a the top of your script. if you see "got here" in your browser window then simply move the

    die( "got here");
 
line further down in your code, save and then preview on front end again.

can take a while but will help you track down where the script is falling over in the absense of any error reports on screen.



    die( "got here");

Open in new window

0
 

Author Comment

by:Desire2change
ID: 24830276
it doesn't stop at a particular line,
at the top there is a loop of  7 ( 7 days as i explained earlier ) , if i run from 1 to 7 the execution stops when it reaches 5
if i run till 5 , the whole output is displayed perfectly, without problem.
but if it is a timeout problem, then why doesn't it show the fatal timeout error

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24831240
Good question here: "but if it is a timeout problem, then why doesn't it show the fatal timeout error"

Probably it is NOT a timeout problem.  It is more likely to be a data-dependent logic error that causes an early exit from the program.  I suggest you use tracking messages, like basic612 suggested.  

Another way to look at this situation is to set the time limit to one second and see if you can get a timeout to occur (just loop a counter or something to use up a second of CPU time).  There is a very tiny possibility that your server or PHP installation is misconfigured in such a way that it suppresses the timeout error message.

Best regards, ~Ray
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Desire2change
ID: 24831255
as I said, it works when i change the topmost loop from 1 to 7 , to 1 to 4
if it was logic problem , it will not work for any kind of loop right ?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24831881
"if it was logic problem , it will not work for any kind of loop right ?"  Well, that depends on what you do in the loop.  If you can post the code, perhaps there is something we might spot, or a more concrete suggestion we might offer.
0
 

Author Comment

by:Desire2change
ID: 24838614
The code is too complex and I cannot paste the url here.
But for you to have an idea I am  just posting a part of the code.
Hope you are able to understand it.....
<div id="chaine_prog1">

            	<div id="loadingid" align="center"><img src="images/ajax-loader.gif" border="0" />

                </div>

				<script type="text/javascript">

						mynewarray=new Array();

					</script>

				<?php

				$xxr=0;

				//die($sunday. "====".$en);

				for($myday=$sunday ; $myday <= ($en-4) ; $myday++) 

				{

					$xxr++;

					$dt_mt = date('Y-m-d H:i:s', mktime($hour_mt[0],$hour_mt[1],0,$mnth, $myday, $year));	

					$dt_mf = date('Y-m-d H:i:s', mktime($hour_mf[0],$hour_mf[1],0,$mnth, $myday, $year));

					$dt_af = date('Y-m-d H:i:s', mktime($hour_af[0],$hour_af[1],1,$mnth, $myday, $year));

					$dt_at = date('Y-m-d H:i:s', mktime($hour_at[0],$hour_at[1],0,$mnth, $myday, $year));		

					$dt_ef = date('Y-m-d H:i:s', mktime($hour_ef[0],$hour_ef[1],1,$mnth, $myday, $year));

					$dt_et = date('Y-m-d H:i:s', mktime($hour_et[0],$hour_et[1],0,$mnth, $myday, $year));	

					$dt_nt = date('Y-m-d H:i:s', mktime($hour_nt[0],$hour_nt[1],0,$mnth, $myday+1, $year));

					$dt_pf = date('Y-m-d H:i:s', mktime($hour_pf[0],$hour_pf[1],1,$mnth, $myday, $year));

					$dt_pt = date('Y-m-d H:i:s', mktime($hour_pt[0],$hour_pt[1],0,$mnth, $myday, $year));

					$dt_nf = date('Y-m-d H:i:s', mktime($hour_nf[0],$hour_nf[1],1,$mnth, $myday, $year));

					

					$fromdate=$dt_mf;

					$todate=$dt_nt;
 

					

				?>

				

                <div id="onewholechineprog<?=$xxr?>" style="display:none;">

					

					<?php

                    $chstr = $cstr;

					$chstr="SELECT * FROM `chaine` WHERE publish='Y' AND kind=1 AND cid IN (".$groupName1.") ORDER BY cid DESC ";

					$chres=mysql_query($chstr);

					$chaine = 1;

					while($data = mysql_fetch_assoc($chres)) {

						$cid = $data["cid"];

						$title = $data['title'];

						$xmlName = $data['xmlname'].".XML";

						if(isset($xmlName) && strlen($xmlName) >0) {

						

						?>

						

						 <!-- déb chaine_prog_<?=$chaine?> -->

    				<div id="chaine_prog">

      					<div class="chaine_logo">

                       		<a href="tvchannel_details.php?cid=<?=$data["cid"]?>" ><img src="images/logo_chaine/<?=$data["logo"]?>" width="89" height="56" border="0" /></a>

                        </div>

    					

						

						<div id="screen<?=$chaine?><?=$xxr?>" class="screen"> <img class="prev" src="images/arrow-left.png" alt="prev" width="20" height="60" />

                <div class="sections" id="section<?=$chaine?><?=$xxr?>">

                  <ul>

						

			       				<script>

									mynewarray["mySlides<?=$chaine?><?=$xxr?>"]=new Array();

								</script>

          						<?				

								$myno=0;

								$tmp=1;

								$tgmp=0;

								$matin=0;

								$smidi=0;

								$butsoire=0;

								$soire=0;

								$nuit=0;

								$tmsn=0;						

							$xmlfile = 'xml/'.$xmlName;

							$assoc=xml_parse_into_assoc($xmlfile);

							$Arrayname = array();

							$k=0;

							$lim1=count($assoc[GRILLETV][JOURNEE]);

							for($jj=0; $jj<$lim1; $jj++) {	

								$lim2=count($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION]);

								for($i=0; $i<$lim2; $i++) {

									

									$title = mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][TITRE]); 

									$date =  mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][DATEHEURE]); 

									$duration = mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][DUREE]); 

									$subtitle = mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][SURTITRE]); 

									$csa = mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][CSA][NOMLONG]); 

									$letexte=mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][EMISSION][LESTEXTES][TEXTE][LETEXTE]); 

									if($letexte=='')

										$letexte=mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][EMISSION][MAGAZINEXY][LESTEXTES][TEXTE][LETEXTE]); 								

										$date = str_replace( 'T', ' ', $date);

										$datarr = explode(' ', $date);

										$dateOnly = $datarr[0];

										if(isset($title) && strlen($title) >0 && isset($date) &&  strlen($date) >0 && isset($duration) && strlen($duration) >0 && isset($dateOnly) && strlen($dateOnly) >0)

										{

										$from = strtotime($fromdate);

										$to = strtotime($todate);

										

										$title = stripslashes($title);

										$subtitle = stripslashes($subtitle);

										$prg_date = stripslashes($date);

										$duration = stripslashes($duration);

										$dateOnly = stripslashes($dateOnly);

										$csa = stripslashes($csa);

										$letexte = stripslashes($letexte);

										$prg_date_str = strtotime($prg_date);

										if(($from <= $prg_date_str)  &&  ($to >=  $prg_date_str) ) {

										

										$Arrayname[$k] = array('date' =>$prg_date, 'duration' => $duration, 'title' => $title , 'subtitle' => $subtitle , 'dateOnly' =>$dateOnly, 'csa' => $csa, 'letexte' => $letexte);

										$singleDetails=$Arrayname[$k];

									$k++;

					

					

					                 

									if($tmp == 4) 

									{ 

										$tmp = 1;

									}

									if($tmp==1)

									{

										//echo '<div>';

									}

									echo '<li>';

									$prog_date_xplode = explode(" ",$singleDetails["date"]);

									$time_xplode = explode(":",$prog_date_xplode[1]);

									$date_xplode = explode("-",$prog_date_xplode[0]);

									$d=date("l", mktime($time_xplode[0],$time_xplode[1],$time_xplode[3],$date_xplode[1], $date_xplode[2],$date_xplode[0]));

									$nd=date("F", mktime($time_xplode[0],$time_xplode[1],$time_xplode[3],$date_xplode[1], $date_xplode[2],$date_xplode[0]));

									if($tmp == 1){

										$title = htmlentities($singleDetails["title"], ENT_QUOTES, 'UTF-8');

										$tit=htmlentities($singleDetails["letexte"], ENT_QUOTES, 'UTF-8');

										?>

          						<div class="box-side">

                                <abbr href="#" title="<span class='title'><?=htmlentities(stripslashes($title))?></span><br><br><?=stripslashes($tit)?><br><br><?=stripslashes($singleDetails["csa"])?><br><?=$singleDetails["duration"]?> min<br><br><strong><?=$time_xplode[0].":".$time_xplode[1]?></strong>&nbsp;">

            <?

											$tmp++;

										}elseif($tmp == 2){

										

										$title = htmlentities($singleDetails["title"], ENT_QUOTES, 'UTF-8');

										$tit=htmlentities($singleDetails["letexte"], ENT_QUOTES, 'UTF-8');

						?>

            <div class="box-side"><abbr href="#" title="<span class='title'><?=htmlentities(stripslashes($title))?></span><br><br><?=stripslashes($tit)?><br><br><?=stripslashes($singleDetails["csa"])?><br><?=$singleDetails["duration"]?> min<br><br><strong><?=$time_xplode[0].":".$time_xplode[1]?></strong>&nbsp;">

              <?

											$tmp++;

										}else{

										

										$title = htmlentities($singleDetails["title"], ENT_QUOTES, 'UTF-8');

										$tit=htmlentities($singleDetails["letexte"], ENT_QUOTES, 'UTF-8');

										

										?>

              <div class="box-side"><abbr href="#" title="<span class='title'><?=htmlentities(stripslashes($title))?></span><br><br><?=stripslashes($tit)?><br><br><?=stripslashes($singleDetails["csa"])?><br><?=$singleDetails["duration"]?> min<br><br><strong><?=$time_xplode[0].":".$time_xplode[1]?></strong>&nbsp;">

                <?

											$tmp++;

										}

									?>

									

									

									<?=$jour[$d]?>

                                    &nbsp;

                                    <?=$date_xplode[2]?>

                                    &nbsp;

                                    <?=$mois[$nd]?>

                                    &nbsp;<strong>

                                    <?=$time_xplode[0].":".$time_xplode[1]?>

                                    </strong><br>

                                    <span class="title">

                                    <?=htmlentities($singleDetails["title"], ENT_QUOTES, 'UTF-8');?>

                                    </span><br><?=$singleDetails["csa"]?><br>

                                    <?=$singleDetails["duration"]?>

                                    min</abbr>

               					</div>

             					 <?

								//if($tmp == 4) {

								 //}

								 echo '</li>';

									

									for($imk=1;$imk<=12;$imk++){

										if(strtolower(trim(date("F", mktime(0, 0, 0, $imk, 1, 2009)))) == strtolower(trim($nd))){

											$monthnumber = $imk;

										}

									} 

								//$monthnumber++;

								$tm = date('Y-m-d H:i:s', mktime($time_xplode[0],$time_xplode[1],0,$monthnumber, $date_xplode[2], $year));

								/*echo "<hr>".$tm;

								echo "<hr>".$dt_af;

								echo "<hr>".$dt_at;*/

								if(strtotime($tm) >= strtotime($dt_mf) and strtotime($tm) <= strtotime($dt_mt) and $matin==0)

								{

									?>

									<script>

										mynewarray["mySlides<?=$chaine?><?=$xxr?>"][<?=$tmsn?>]=<?=$myno?>;

									</script>

									<?php

									$tmsn++;

									$matin++;

								}
 

								if(strtotime($tm) >= strtotime($dt_af) and strtotime($tm) <= strtotime($dt_at) and $smidi==0)

								{

								?>

								<script>

									mynewarray["mySlides<?=$chaine?><?=$xxr?>"][<?=$tmsn?>]=<?=$myno?>;

								</script>

								<?php

								$tmsn++;

								$smidi++;

								}

								if(strtotime($tm) >= strtotime($dt_ef) and strtotime($tm) <= strtotime($dt_et) and $butsoire==0)

								{

									?>

									<script>

										mynewarray["mySlides<?=$chaine?><?=$xxr?>"][<?=$tmsn?>]=<?=$myno?>;

									</script>

									<?php

									$tmsn++;

									$butsoire++;

								}

								if(strtotime($tm) >= strtotime($dt_pf) and strtotime($tm) <= strtotime($dt_pt) and $soire==0)

								{

									?>

									<script>

										mynewarray["mySlides<?=$chaine?><?=$xxr?>"][<?=$tmsn?>]=<?=$myno?>;

									</script>

									<?php

									$tmsn++;

									$soire++;

								}
 

								if(strtotime($tm) >= strtotime($dt_nf) and strtotime($tm) <= strtotime($dt_nt) and $nuit==0)

								{

									?>

									<script>

										mynewarray["mySlides<?=$chaine?><?=$xxr?>"][<?=$tmsn?>]=<?=$myno?>;

									</script>

									<?php

									$tmsn++;

									$nuit++;

								}

									$myno++;

								

								

												}

									}

								}

							}

						}
 

								

								//end for loop

								//if($tmp<4)

									//echo '</div>';

								?>

           

			 <!-- end panel -->

        		

		 			 </ul>

		   			

                   </div>

				    <img class="next" src="images/arrow-right.png" alt="prev" width="20" height="60" /></a>

                  </div>

				  </div>

                <!-- fin chaine_prog -->

                  

                <?

                            $chaine++;

                          

                                

            }//end while			

                    ?>

        

        

        </div>  <!-- finished div one whole chaine programme -->

		<?

		}

		?>

Open in new window

0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24840755
@Desire2change: I think you hit the nail on the head with this statement: "The code is too complex."

There is ZERO chance I will be able to understand it.  You have n-dimensional arrays and no comments anywhere in sight.  Not trying to be rude to you, but I would fire a programmer who presented something like this.  

Some things you might want to consider (in addition to adding comments to the code)...

Avoid the use of the short_tags - programming that produces incompatibility with XML is not really a habit you want to develop.

Consider learning about Object-Oriented Programming.

Consider reducing the use of redundant and unnecessary functions and variables.  In the code snippet you will find a few lines extracted from the snippet posted above.  They are listed in the order they appear in the code.  It seems throughout the programming there are a lot of "non-value-added" structures that can be eliminated or revised in such a way that the overall execution time would go down dramatically.  For example, I found 22 occurrences of strtotime() - often repeated with the same variable.  Why not compute the timestamp once and store it?

I will sign off on this question now.  You need to put in some data and logic visualization structures, and we have shown you how to do that.  Best of luck with it, ~Ray
// COPY AND ESCAPE A VALUE INTO THE VARIABLE $date 

 $date = mysql_real_escape_string($assoc[GRILLETV][JOURNEE][$jj][DIFFUSION][$i][DATEHEURE]); 
 

// ELIMINATE THE LETTER 'T' FROM THE DATE - WHAT POSSIBLE USE IS THIS?

 $date = str_replace( 'T', ' ', $date);
 

// TEST TO SEE IF THE $date VARIABLE IS SET - IT HAS TO BE SET BECAUSE OF THE CODE THAT CAME BEFORE

 if(isset($title) && strlen($title) >0 && isset($date) && strlen($date) >0 && isset($duration) && strlen($duration) >0 && isset($dateOnly) && strlen($dateOnly) >0)
 

// COPY AND REMOVE THE ESCAPE CHARACTERS FROM THE VARIABLE $date

 $prg_date = stripslashes($date);
 

// MAKE A TIMESTAMP OUT OF THE COPIED DATE

 $prg_date_str = strtotime($prg_date);
 

// UNNECESSARY RECOMPUTATION USING strtotime()

if(strtotime($tm) >= strtotime($dt_ef) and strtotime($tm) <= strtotime($dt_et) and $butsoire==0)

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now