PHP - Execution Of A Php Code Takes Too Long
I have a very weird problem on my PHP5.3/Apache/MySQL based system on WinXp Pro.
I have written php script which basically scans every directory in my local hard disc, checks which files are images, sets a counter of the number of images found per folder and saves this count in a MySQL table. To put you in the picture, we are talking about 1000 folders with about 8-10pics each on average 9000 files. On the previous PHP 5.1 / IIS system, (same PC) this used to work moderately well (took a nice 6 mins) and I had to include the command set_time_limit of about 3seconds in the looping to avoid execution timeout failures. (also worked by setting a high value of 10mins before the loopping) ANyway, now I run the exact same script on the new Php5.3 and have the problem that the code starts operating quite fast and gradually it slows and slows until eventually it is dead slow and have to quit internet explorer. For exampe, the first 3000 files are scanned in just 60seconds, then the next 1000 in the next 4 mins, and eventually drops to about 100files or less files per minute. I also noticed that the CPU consumption of iexplorer.exe is 90-99%, and the window of Internet explorer is very slugish with a temp '(not responding)' messages on the top window bar. WHat can I do and test? Is it the code itself, the PHP5.3 or something in php.ini or apache conf. file? Buffers? memory? WHat? gonna crazy! basically, the code scans a dir (location of dir taken from Mysql) puts file contents in an array, analyse the array for .jpg/.gif (and other parameters specific to pics, counts the valid pic files in a variable, puts this in a MySql databse, loops for next folder. The code is a kind of tool to have a count of my pics in my folders and never used remote server/online but only local. Thanks for your time Similar TutorialsGuys, why the following mysql stored procedure taking much more time comparing with firebird one?
1. MySQL stored procedure
CREATE DEFINER=`lxc`@`::1` PROCEDURE `insertData`(IN it INT) BEGIN declare i int Default 0; declare str char(4); declare p_hash int; myloop: loop set p_hash = round(rand() * 999); set str='book'; insert into test.users (name,password) VALUES (concat(str,'_',i+1),PASSWORD(p_hash)); set i = i+1; if (i = it) then leave myloop; end if; end loop myloop; endObject info: Table: users Columns: id int(10) UN PK AI name varchar(45) password char(41)Time: mysql> call insertData(10000); Query OK, 1 row affected (9 min 38.22 sec)2. Firebird Stored Procedure SET TERM ^ ; CREATE PROCEDURE INSERDATA ( IT integer ) --iteration number AS DECLARE VARIABLE i integer; BEGIN i = 0; while ( i < it ) do begin INSERT INTO PRODUCT( CODE,NAME,PASS) VALUES(:i, 'jazz_' || :i, fb_hash(round(rand() * 999))); i = i + 1; end END^ SET TERM ; ^ COMMIT;Object Info: Table: product columns CODE integer, NAME varchar(45), PASS CHAR(41)Time: ( for 10 000 records it takes less than 1 sec for execution) Executing statement... Statement executed (elapsed time: 0.063s). 31464 fetches, 11084 marks, 0 reads, 0 writes. 10000 inserts, 0 updates, 0 deletes, 5 index, 0 seq. Delta memory: 24264 bytes. PRODUCT: 10000 inserts. 0 rows affected directly. Total execution time: 0.151s Script execution finished.Do you see something wrong in mysql stored procedure code? jazz. Edited by jazzman1, 31 July 2014 - 03:21 PM. I am trying call an R batch file inside php script from browser. The R script basically generate an imgae and save in a folder. Unfortunately, I could call the R within php (means that no image is saved in the folder) using BROWSER. But when I run the php script from the commadline, it works and image is saved in the folder.
<?php exec("Rscript /var/www/html/phil/figs/map.R"); ?>Execuition of following R batch code and php codes work and save image in the specified folder from the terminal. 58A-UD3R:~$ php /var/www/html/phil/x.php 58A-UD3R:~$ Rscript /var/www/html/phil/figs/map.RI totally in confusion why browser cannot successfully save image. Or is there anythinng need to be change in server for generating image? Anyone please help me for solving this probelm. Thank You.. Dear Friends I want to execute a php code when my session has been destroy or demoinshed, I need a help regarding this kindly help me. Best Regards Habib I have several registration systems that were designed some time ago running mysql. How long do I have until I have to competely move to mysqli? I am working on recoding them, but it is taking some time. Does anyone know when it will become an issue?
"BACK" or REFRESH: Preventing database interaction / code execution how to prevent database interaction / code execution when user presses back or refresh button? can i detect? can i disable back/refresh? my server is using sendmail, but it takes about 60 seconds to send. And by send, i don't mean to recieve the message. I just have a simple mail call, and when i hit that page it takes about 60 sec to return a result to me. I look for a while on what might be causing, but i can't seem to find anything that i can test out. Anyone ever have this know whats going on? Hello Coders, Iam in a confused situation. I made a php script & in that script i want to check how much time (in seconds) the page is taking to fetch the content from the server. If the time is greater than to i defined time then i want to show a error message to the users. Anybody can give me ideas ..................... ??
$start = 0; I have a script to write out the number of hits each of my websites got each day of the week since I don't trust Google Analytics spying on my websites. The problem is that I have to query each day individually and count how many instances there are with that domain. Since I setup my database give me the time, location, demographics, etc. on each line I'm not sure how to optimize this further. Help would be greatly appreciated. Code: [Select] echo '<table><tr><td>Domain</td>'; foreach($timearray as $t){ echo '<td>'.$t.'</td>'; } echo '</tr>'; $i = 0; foreach($urlarray as $u){ $today = date("Y-m-d"); $yesterday = date("Y-m-d", mktime(0,0,0,date("m") , date("d")-1, date("Y"))); $lastmonth = date("Y-m-d", mktime(0,0,0,date("m")-1 , date("d")-1, date("Y"))); $twoweeks = date("Y-m-d", mktime(0,0,0,date("m") , date("d")-15, date("Y"))); $result3 = mysql_query("SELECT refer,Count(*) as count FROM `approved` WHERE time>'$lastmonth 23:59:59' AND time<'$today' AND refer LIKE '%$u%'"); $row3 = mysql_fetch_array($result3); $result4 = mysql_query("SELECT refer,Count(*) as count FROM `approved` WHERE time>'$twoweeks 23:59:59' AND time<'$today' AND refer LIKE '%$u%'"); $row4 = mysql_fetch_array($result4); if($row3['count']==0){echo "<tr style='background:red'>";}elseif($row4['count']>0){echo "<tr style='background:green'>";}elseif($i % 2){echo "<tr style='background:#CCC'>";}else{echo "<tr style='background:#FFF'>";} echo '<td>'.$u.' '.$row3['count'].' '.$row4['count'].'</td>'; foreach($timearray as $t){ $result = ''; $result = mysql_query("SELECT COUNT(*) AS count FROM `approved` WHERE time LIKE '$t%' AND refer LIKE '%$u%'"); while($row = mysql_fetch_array($result)){ echo '<td>'.$row['count'].'</td>'; } } echo '</tr>'; $i++; } echo '</tr></table>'; Is there a way in php to not execute the whole script if there is error on the script? For example: Code: [Select] <?php execute script here; .......... ........... [b] error encounter here[/b]. -> error is not logical execute script ............. ............. ?> I don't want to execute the above script... tnx everyone. Hello, I am developing an account manager for our local network and I want people to be able to login to my website and change their UNIX & Mailbox password. These people have SSH access so that is why the UNIX passwd should also be changed. So what I want to do is get the values $username, $currentpwd , $newpwd and $newpwdcnfrm from the HTML form and execute the following shell commands : Quote su -l $username passwd Enter current UNIX Passwd : $currentpwd Enter new UNIX Passwd : $newpwd Confirm UNIX Passwd : $newpwdcnfrm The problem here is, passwd takes old and new passwords as input, not as command parameters. So I cant just do shell_exec("passwd $currentpwd $newpwd $newpwdcnfrm") ; Do you guys know how to give input to the command? thanks. Btw : Please do not argue about the security issues. I am aware of everything and I am perfectly sure that the script will run securely. hey guys... below is my code... when i hit the "submit" button the browser displays the php file rather than writing to the db... can anyone see what im doing wrong .. thanks Code: [Select] <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="insert_ac.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Lastname</td> <td>:</td> <td><input name="lastname" type="text" id="lastname"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </td> </tr> </table> Code: [Select] <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $lastname=$_POST['lastname']; $email=$_POST['email']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Hi,
I have this code:
<div id="pics"> <?php if (count($itemRow['pics']) == 0) { ?> <img src="<?php h("{$www_base}/none.jpg"); ?>" class="pic active" /> <?php } else { ?> <?php for ($i = 0; $i < count($itemRow['pics']); $i++) { ?> <img src="<?php h(getThumbnail($itemRow['site'], $itemRow['pics'][$i])); ?>" class="thumbnail<?php if ($i == 0) e(" active"); ?>" picnum="<?php h($i); ?>" /> <?php } ?> <div style="clear:both;"></div> <br /> <?php for ($i = 0; $i < count($itemRow['pics']); $i++) { ?> <a target="_blank" href="<?php h(getPicture($itemRow['site'], $itemRow['pics'][$i])); ?>"> <img src="<?php h(getPicture($itemRow['site'], $itemRow['pics'][$i])); ?>" class="pic<?php if ($i == 0) e(" active"); ?>" /> </a> <?php } ?> <?php } ?> </div>This code practically take a picture and post it on my website, but the problem is that is also take the superfish advertisement, that I can see only in the html source. <div id="similarproducts_inimg" class="__similarproducts similarproducts_inimg generic generic" style="left:15px; top:465px;"><div class="container"><div class="explore_button _open_full_ui" style="height:100px; background-image: url('http://www.superfish.com/ws/images/inimg2/explore_en.png');" data-report-action="explore click"><div class="label"></div></div><a class="item free_shipping _merchant_click" target="_blank" href="http://www.........................</div></div>How I can block a specific DIV to be created. I try some java-script and no success until now. Some other solutions? i wanna put condition that if ($signupbonus > 0.00) then following should not be executed <font size="3" color="red"><b>Referral bonus: <font color="green" size="4">$<? echo $signupbonus; ?></font></b></font><br><br> please help Hi All,
I'm hoping somebody would be able to help me with a performance issue I'm having with a bit of code I've written.
The setup:
Client request arrives on Apache2 reverse proxy over HTTPS. SSL is offloaded and proxy initiates connection to backend development web server over standard HTTP. The website is being developed using HTML5 syled with CSS, Javascript (to dynamically show counters on message text area, perform client side validation for browsers that do not support the build in HTML5 input validation) and PHP for server side validation and form submission (sends email to webadmin).
The development web server is located in a LXC container on the production web server. The host server presents the "public" IP address to the physical network and uses UFW to NAT all traffic inbound and outbound from the development website to trick the network into thinking that the server is on the physical network (Only way to get it routeable across the rest of the network).
The problem:
On form submission, if I intentionally leave the fields blank and turn off client side validation, the script echos "An error occured in your form, please check to make sure that all relevent fields are filled in!!!". This response returns in 16.50ms with a latency of 34.92ms. The POST appears instantly in the Apache2 logs less than a second after I submit the form.
If I submit the form with all fields (Name, Email, Phone, Website, Subject and Message), it takes 60 - 65 seconds before Apache logs the POST has arrived. I'm not entirely sure why its taking this long for the server to receive the content. GET Requests are pretty much instant as I would expect. Could this be an issue with inefficient scripting that maye be causing this type of delay? This issue occurs regardless of whether I use firefox or Safari.
Could this be a result of inefficient scripting? Using timelines in Safari and on form submission with content, I get 1.0min latency with an actual duration/script run time of 5.336ms. Where would this latency be coming from? Standard GET requests for HTML and CSS content is instant, next to no latency but once the Payload increases in size, it seems like I run into the issue.
Any views, thoughts or possible things to try would be hugely appreciated. I'm learning the ropes with scriping at the moment but this high latency, as a hunch, appears to be server related. Happy to upload the submit.php script and web form if it will help.
Many Thanks,
A
Hello, i've been coding a CLI php mailer which i'm using with a webshell. My problem shows up when i execute my mailer, the hole server crash or in the best case scenario it slows down a lot. In the same folder that my script was executing a huge error log appears with this error repeated: Quote PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-zts-20060613/sqlite.so' - /usr/local/lib/php/extensions/no-debug-zts-20060613/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-zts-20060613/pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-zts-20060613/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-zts-20060613/ixed.5.2ts.lin' - /usr/local/lib/php/extensions/no-debug-zts-20060613/ixed.5.2ts.lin: cannot open shared object file: No such file or directory in Unknown on line 0 I'm not getting why this happens since i just use normal functions like mail(), fread(), etc. I'm not using any sql function or anything like that. Any clues? Another non related thing i wanted to ask was: Is it possible to make an "interactive" cli script? I mean using a similar function like getc() in C or something. I would like to have a script that would check certain parameters and if none of them returns TRUE, execute a set of codes. So the idea is somehow like if...else(). Code: [Select] <?php // trying to put if() directly within if() if ( // checking of variables if (!isset($transaction)) { echo '<font color="#FF0000">Type of transaction is not set.</font>'. '<br />'; } else { if ($transaction == 'sell') { if (empty($BV)) { echo '<font color="#FF0000">Book value is not set.</font>'. '<br />'; } } } if (empty($stock)) { echo '<font color="#FF0000">Stock symbol is not set.</font>'. '<br />'; } if (empty($price)) { echo '<font color="#FF0000">Price per share is not set.</font>'. '<br />'; } if (empty($volume)) { echo '<font color="#FF0000">Volume of shares is not set.</font>'. '<br />'; } ) { echo 'Go back and fill out necessary fields.'; } // if none of the above parameters returns TRUE else { echo 'Copy and paste the following in the email that you would be submitting.' </tr> <tr> <td> switch ($transaction) { case 'buy': include('calc_buy.php'); break; case 'sell': include('calc_sell.php'); break; default: echo '<font color="#FF0000"><b>If you see this message there is something wrong with your session. Please send us a feedback with the details of your session before seeing this message.</b></font>'; } } ?> This code returns an error and as I understand the error, it is because of if (if ()). How can I make it work? Thanks in advance! Hey guys, I was wondering if it is possible to have a value inserted into a table as someone clicks on a link (in order to count views for example)? thanks! I have this one issue. While logging in into our system, we call a routine called getToken(). This calls a routine on another server (used to be able to securely access documents). The issue we have is if that other server goes down, this call fails, and the user isn't able to login. I want to make it so that even if the other server goes down, users can still login and access our system (just not documents). I know that I can't prevent fatal errors or even ignore them, correct (even with set_error_handler)? Any thoughts? It's a simple call, here's all it is: require_once('include/utils.php'); $token=getToken(); Code: [Select] <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect($hostname, $username, $password); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db($dbname); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<ul class="err">'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo '<li>',$msg,'</li>'; } echo '</ul>'; unset($_SESSION['ERRMSG_ARR']); } session_write_close(); header("location: index.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_field($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> This is my login execution script and when i run it, i get this - Fatal error: Cannot use object of type stdClass as array in /home/a8029060/public_html/login-exec.php on line 75 Please any help :/ |