PHP - Website Run Very Slow
Hi,
I coded this website in php http://www.3gar.info but it seem very slow. I checked the server but they said everything is ok and the website run smoothly in server. I have another copy of this website in hostmonister it run very fast there. http://www.ibuj.org Similar TutorialsOk, so basically someone submits a file (doc) and I need to see if it is the same as another file. So instead of opening 300+ files and checking for word similarity, I put the file info into a table called newnotes. Then check the file size for each of the notes in "newnotes" against all of the notes in the table "approvednotes" this could be something like matching 20 file sizes to 300+ file sizes. The user gets returned back to a page and this is all done in backend by the click of a button the admins can use. But would doing this slow down my server/website? would Java handle it faster? can PHP be made to handle it as fast? I really need help. check out my website and search cars for sale, then any distance and then 37919 zip. it takes too long and there are only 3351 cars on there now. before, when it only had about 2200 cars it was really fast. only about a 1000 cars made it slow. what could it be? nabacar.com It was returning results in about 15 seconds or less with 2200 cars. Now it is over a minute with only 1000 cars on it. I will have 150,000 on it when I get this sorted. http://nabacar.com some java was written to speed things up, but it didn't seem to help. Is it the server or the code causing this? I am aiming to use setcookie to refresh the expiry of a cookie on EVERY page request. Is this slow? I'm sure I can design things so i don't need to reset it on every page request, but if it isn't a big deal then I'll do it. Is setcookie slow? Hi, I am having a problem with a part of my query: "SELECT SQL_CALC_FOUND_ROWS jobs.id AS jobId, enquiries.id AS profId, users.username, entity_details.name AS entityName, branches.name AS branch, orderNumber, entity_vat_numbers.vatCode, entity_account_numbers.accountNumber, (SELECT symbol FROM parts_trading, currencies WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = currencies.id LIMIT 1) AS symbol, (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) AS differentPartsCount, (SELECT SUM(quantity*sellingNet) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.net) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS netRemaining, (SELECT SUM(quantity*sellingVat) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.vat) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS vatRemaining, (SELECT SUM(quantity*(sellingNet+sellingVat)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.net+invoices_out.vat) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS totalRemaining FROM jobs, enquiries, users, branches, entity_details LEFT JOIN entity_account_numbers ON entity_details.id = entity_account_numbers.entityRef LEFT JOIN entity_vat_numbers ON entity_details.id = entity_vat_numbers.entityRef WHERE enquiries.traderRef = users.id AND jobs.enquiryRef = enquiries.id AND users.branchRef = branches.id AND (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) > 0 AND enquiries.entityRef = entity_details.id" I know for certain that it is the part: "AND (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) > 0" That is causing the problem. Unfortunately this is a vital part of my query used for not displaying rows that have quantities matching the sum of what is in the other table . Is there are more efficient way to get the same result than that part of the query? hey i have a problem when i try to send email through php it seems to take a long time somethings it can be there quickly but somethings it takes forever is it something im doing wrong in the short script this is part of my script Code: [Select] // email profile owner $webmaster = "admin@website.com"; $headers = "From: mywebsite<$webmaster>"; $subject = "$username has commented on your profile"; $message = "Hello $firstname $lastname. $username has posted a comment on your profile on mywebsite.com"; $message .= " The message $username has posted with is below.\n"; $message .= "\n****************************************************************\n"; $message .= "$comment"; $message .= "\n\n****************************************************************\n\n"; $message .= "Click here to view $username's profile $site/profile?id=$userid\n"; $message .= "Click here to view your profile $site/profile?id=$getid\n"; // send email mail($email, $subject, $message, $headers); I have swift mailer setup to send two message and plain and HTML. I have followed a lot of different posts and came up with a solution that works. However when I send for example 7k emails only about 500 made it out before the 30sec timeout. So I switched my timeout to 600secs and only about 3k made it out. I now I can switch my timeout to 0 or 3600sec and it will go through but it doesnt seem like this should take so long. I use Debian 6.0, Zimbra 7, Postfix, and SwiftMailer I am using the mailer like this; / Create the Transport $transport = Swift_SmtpTransport::newInstance('localhost', xx) ->setUsername('xxx') ->setPassword('xxx') ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); //Starts the loop to separate the to email addresses everything past here is built for each email $to1 = explode(", ", $to); for($i = 0; $i < count($to1); $i++){ // Create a message $message = Swift_Message::newInstance($subject) ->setFrom(array($from => 'xxx')) ->setTo(array($to1[$i])) ->setBody($plaintxt) ->addPart($htmltxt, 'text/html'); $plaintxt = substr($plaintxt, 0, -$plaindumplength); $htmltxt = substr($htmltxt, 0, -$dumplength); $emailcounter += $mailer->send($message); } Ok so I have a single mySQL database on a dedicated server hosted through hostgator.. In this database I have 1 table that is a very large table it has well over 900,000 rows on it and we anticipate another 8.1 million records to be added within another 6 months and from there expect the table to grow regularly. Right now my issue is and can only foresee it getting worse as the size gets larger. Is that my queries are running slower and slower. Sometimes even resulting in the DB crashing. So what I am trying to figure out is how do I speed this up. I've tried 101 ways to query the DB to speed it up and can't get it to load 10 results 10.. in less than 30 seconds. I know some of my issue is the fact that I need distinct results or unique ones rather. As there are several duplicate entries but I only need to pull out one of each for this particular function which is a search. So that said is there any advice one can give me to speed up my query results. I would offer up a sample of my current queries but its just your common query using distinct. Hi everyone, I have a data analysis system which, however, takes too long to insert data into the db. Can you help me understand where I went wrong? thank you DB MYSQL:
1 analytics_number bigint(20) AUTO_INCREMENT --------------------------------------------------------------------------- CLASS PHP Analytics.php class analytics {
public $search_sites; public function get_analytics_enter($visitor_ip, $visitor_visitor_id, $visitor_session_id, $visitor_pageview_id, $visitor_referrer, $visitor_url, $visitor_resolution, $visitor_viewport, $visitor_document){ try{
$GET_array = array("visitor_ip" => $visitor_ip, "visitor_visitor_id" => $visitor_visitor_id, "visitor_session_id" => $visitor_session_id, "visitor_pageview_id" => $visitor_pageview_id, "visitor_referrer" => $visitor_referrer, "visitor_url" => $visitor_url, "visitor_resolution" => $visitor_resolution, "visitor_viewport" => $visitor_viewport, "visitor_document" => $visitor_document);
$query = "SELECT * FROM analytics WHERE visitor_visitor_id = '".$visitor_visitor_id."'"; $visitor_ip_info = get_data_visitor($visitor_ip);
$visitor_visitor_pageview = 0;
$session_buffer = array();
$visitor_visitor_pages = array();
$analytics["visitor_session_landingpage"] = NULL;
foreach ($visitor_data as $visitor) {
if (!in_array($visitor["visitor_page_path"], $visitor_visitor_pages)) {
if ($visitor["visitor_session_id"] == $visitor_session_id) {
if ($visitor_session_pageview == 1) {
if (!in_array($visitor["visitor_page_path"],$visitor_session_pages)) {
if (!in_array($visitor["visitor_session_id"],$session_buffer)) {
if (!in_array($visitor_session_id,$session_buffer)) {
foreach($GET_array as $key => $value) {
$analytics["visitor_visitor_sessions"] = $visitor_visitor_session;
$analytics["visitor_visitor_pageviews"] = $visitor_visitor_pageview + 1; $analytics["visitor_visitor_time"] = "0";
$analytics["visitor_session_pageviews"] = $visitor_session_pageview + 1;
$analytics["visitor_enter_timestamp"] = date("d.m.Y, H:i:s");
$analytics["visitor_leave_timestamp"] = date("d.m.Y, H:i:s"); $analytics["visitor_pageview_time"] = "0";
$analytics["visitor_country"] = $visitor_ip_info["country"];
$analytics["visitor_referrer_url"] = $visitor_referrer;
$analytics["visitor_domain"] = $this->get_domain($visitor_url);
if (!in_array($analytics["visitor_page_path"], $visitor_visitor_pages)) {
if (!in_array($analytics["visitor_page_path"], $visitor_session_pages)) {
$analytics["visitor_visitor_pages"] = json_encode($visitor_visitor_pages);
if ($analytics["visitor_session_pageview"] == 1) {
$sql_1_1 = "UPDATE analytics SET " . "visitor_visitor_last_page" . "='" . "" . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_1 = $sql_1_1."; ".$sql_1_2.";";
$analytics["visitor_visitor_last_page"] = "true";
$analytics["visitor_device"] = visitor_device(); $analytics["visitor_pageview_update"] = date("YmdHis");
$sql_2_1 = "INSERT INTO analytics ("; $this->_db->exec($sql_2_1); $sql_2_2 = "UPDATE analytics SET " . "visitor_visitor_sessions" . "='" . $analytics["visitor_visitor_sessions"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'"; $sql_2_3 = "UPDATE analytics SET " . "visitor_visitor_pageviews" . "='" . $analytics["visitor_visitor_pageviews"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'"; $sql_2_4 = "UPDATE analytics SET " . "visitor_visitor_pages" . "='" . $analytics["visitor_visitor_pages"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'"; $sql_2_5 = "UPDATE analytics SET " . "visitor_session_pageviews" . "='" . $analytics["visitor_session_pageviews"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'"; $sql_2_6 = "UPDATE analytics SET " . "visitor_session_pages" . "='" . $analytics["visitor_session_pages"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'"; $sql_2_7 = "UPDATE analytics SET " . "visitor_session_landingpage" . "='" . $analytics["visitor_session_landingpage"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'"; $sql_2_8 = "UPDATE analytics SET " . "visitor_session_exitpage" . "='" . $analytics["visitor_session_exitpage"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'";
$sql_2 = $sql_2_2.";".$sql_2_3.";".$sql_2_4.";".$sql_2_5.";".$sql_2_6.";".$sql_2_7.";".$sql_2_8.";";
} catch(PDOException $e) { public function get_analytics_update($visitor_visitor_id, $visitor_session_id, $visitor_pageview_id, $visitor_pageview_time, $visitor_leave_url){
try{ $query = "SELECT MAX(" . "visitor_session_time" . ") FROM analytics WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "' AND " . "visitor_session_id" . "='" . $visitor_session_id . "' ORDER BY " . "visitor_enter_id" . " DESC LIMIT 1"; $visitor_session_time = $this->_db->query($query)->fetchColumn();
$query = "SELECT MAX(" . "visitor_pageview_time" . ") FROM analytics WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "' AND " . "visitor_session_id" . "='" . $visitor_session_id . "' AND " . "visitor_pageview_id" . "='" . $visitor_pageview_id . "' ORDER BY " . "visitor_enter_id" . " DESC LIMIT 1"; $analytics = array();
foreach($GET_array as $key => $value) {
$analytics["visitor_leave_timestamp"] = date("d.m.Y, H:i:s");
$analytics["visitor_visitor_time"] = $visitor_visitor_time + ($visitor_pageview_time - $visitor_pageview_time); $analytics["visitor_pageview_update"] = date("YmdHis");
if (isset($visitor_leave_url)) {
$sql_1_1 = "UPDATE analytics SET ";
} catch(PDOException $e) {
function visitor_referrer_type($referrer) {
if ($referrer == "") {
$referrer = explode(".",$referrer);
if (array_key_exists($referrer,$search_sites)) {
function visitor_referrer_name($referrer) {
if ($referrer == "") {
$referrer = explode(".",$referrer);
if (array_key_exists($referrer,$search_sites)) {
function visitor_leave_type($leave_url)
if ($leave_url == "") {
if (strpos($leave_url, $url_paz) !== false) {
function visitor_leave_name($leave_url) $leave_url = $this->get_domain($leave_url);
$leave_url = explode(".",$leave_url); } ?> analytics-db.php
<?php // Dataset IDs
array_push($database_structure["analytics"],"visitor_visitor_id"); // Dataset Visitor Data
array_push($database_structure["analytics"],"visitor_visitor_sessions"); // Dataset Session Data
array_push($database_structure["analytics"],"visitor_session_pageviews"); // Dataset Pageview Data // Dataset Enter Time
array_push($database_structure["analytics"],"visitor_enter_timestamp"); // Dataset Leave Time
array_push($database_structure["analytics"],"visitor_leave_timestamp"); // Dataset Geolocation
array_push($database_structure["analytics"],"visitor_country"); // Dataset Technology
array_push($database_structure["analytics"],"visitor_device"); // Dataset Referrer
array_push($database_structure["analytics"],"visitor_referrer_url"); // Dataset Page
array_push($database_structure["analytics"],"visitor_url"); // Dataset Time array_push($database_structure["analytics"],"visitor_pageview_time"); // Dataset Leave
array_push($database_structure["analytics"],"visitor_leave_url"); // Dataset Update
array_push($database_structure["analytics"],"visitor_pageview_update"); analytics-enter.php <?php
if(isset($_POST["visitor_ip"])){ ?> analytics-update.php <?php $analytics->get_analytics_update($_POST["visitor_visitor_id"], $_POST["visitor_session_id"], $_POST["visitor_pageview_id"], $_POST["visitor_pageview_time"], $_POST["visitor_leave_url"]); ?> JS FILE $(function(){
function create_cookie(name,value,days) {
var host = window.location.hostname;
document.cookie = name+"="+value+expires+"; path=/; domain=." + domain;
function read_cookie(name) {
while (c.charAt(0) == ' ') {
if (c.indexOf(nameEQ) == 0) {
function random_string(length, chars) {
function create_id() {
function create_visitor_visitor_id() {
function visitor_visitor_id() {
function create_visitor_session_id() {
function visitor_session_id() {
if (new URL(window.location.href).searchParams.get("analytics") != "true") { var analytics_script_location = "/analytics/controllers/";
var screen_width = screen.width;
var viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var document_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var visitor_ip;
var visitor_visitor_id = visitor_visitor_id();
var visitor_enter_time = new Date();
var visitor_resolution = screen_width + "x" + screen_height; var visitor_leave_url = "NULL"; var current_time = 0;
var scroll_sum = 0;
var visitor_enter_sent = false;
var current_viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var current_viewport = current_viewport_width + "x" + current_viewport_height;
var current_document = current_document_width + "x" + current_document_height;
function track_a_href(event) {
function analytics_visitor_enter() {
$.ajax({
function analytics_visitor_update() {
$.ajax({
window.setInterval(function() {
function analytics_visitor_leave() {
function visitor_leave_delay(time) {
$(window).load(function() { analytics_visitor_enter(); }); } }); Let's say I have a forum with 300 active people posting 24/7 I have error reporting turned off. But if I turn it on, it shows 100-200 Undefined variable's error's on each forum page, even if it's off does it effect performance or does it matter if the php is writing to a error_log? If so how can I disable php writing to a error_log as I have no sense or no need for it. Thanks, and would the speed be noticable if I went ahead and fixed all the errors, if it would help? or no I code fine, it's just i dont use the isset.. Hi Guys We have had a holiday program written in php in the past by an experienced developer but we are experiencing problems now. So I am curious to try and resolve the best approach Here goes 1: We query multiple APIs to return holiday results to our users 2: This can take up to 20 seconds to return results but sometimes its much quicker depending on the volume of API returned results 3: Other users seem to be locked out of even visiting our website if an API call is running So initially without posting any code, I have a couple of questions which are A: Is there a way to maybe poll a process or allow partial results to the users browser while things run in the background ( similar to what other holiday providers seem to be doing ) B: Is there a way to speed this up or maybe some sort of better technology to utilise
Many thanks professionals I have the following simple code to test against collision on a primary key I am creating: Code: [Select] $machine_ids = array(); for($i = 0; $i < 100000; $i++) { //Generate machine id returns a 15 character alphanumeric string $mid = Functions::generate_machine_id(); if(in_array($mid, $machine_ids)) { die("Collision!"); } else { $machine_ids[] = $mid; } } die("Success!"); Any idea why this is taking minutes to run? Anyway to speed it up? I have this code below in a while loop, that gets looped through about 10 times and is simply resizing a slightly larger image to fit within a 50px max square. There is other code on my page, but I've narrowed the slowness down to this specific bit of code (i.e. if I take this snippet out, the page loads instantly). With this snippet, the page takes between 5 and 10 seconds to load, which seems absurd for 10 images. FYI, the original images are no larger than 200 px on either side, so it's not like it's looping through large image files. Anyone know why this might be taking so long? Should I be doing it differently somehow? Code: [Select] list($width,$height) = getimagesize($myimage); if ($width > $height) { $datasofar .= "width=50 /></span>"; } elseif ($height > $width) { $datasofar .= "height=50 /></span>"; } else { //height and width must be equal so just set width = 50, but could just as easily set height to 50 $datasofar .= "width=50 /></span>"; } I have a simple php script without mysql database. Normally it takes less than 1s to complete the process. But in high traffic (more than 10 concurrent processes), the execution time dramatically increases to 10-30s. This itself causes an increase in the concurrent processes. I think this behavior is not very common. Any idea? Btw, can huge error logs make the system slow? I have numerous php notices and it's growing. Hello,
I have a secure login script that uses sessions to maintain a users logged in status. I regenerate the session ID on each page reload for added security. Sometimes, I will lose sessions, and I am hard time figuring out why. It seems to be when I have a slow internet connection. I am wondering what could be causing this?? I have a few ideas, do any of these seem plausible.
-A max execution error, returns a fatal error.
-An ajax request get sent before the previous request returns, so the session ID's dont match an I am kicked out.
Any other ideas would be helpful.
Best,
James
Hello, Hello, I'm using php's mail function to send sms messages to my sprint phone. Sometimes I receive the text right away and other times it comes in as much as an hour or so later. My server is on GoDaddy. Does anyone have any ideas about what could be causing the bottleneck? To debug this I tried sending sms messages from my comcast email. So far those are always received very quickly. Perhaps the issue is on the GoDaddy server... I might try contacting them. By the way, it seems like the first text I send is received quickly, but then if I send other text messages within some short time frame, those don't always show up immediately. Has anyone else experienced anything similar? Hi guys I need some help with slow connection to remote mysql database.
I've been after this for a couple of days. I've been reading around but I didn't find any solution which helped me. I have this scenario:
Server A e-commerce running mysql database running Server B e-commerce running remote connection to server A database The two e-commerce are identical. On server A it runs very quick, on server B the connection to mysql database it's about 16 times slower. Some complex queries and mixes queries don't get resolved and let the page go in timeout. I tried a test php script where I connect to mysql and I run a simple query (some classes are required before the query). On server A execution time is 0.107 seconds while on server B it is 1.788 seconds. I tried to have the same test with both firewall (server A and B) turned off but the results is exactly the same. I added in my.cnf of server A skip-name-resolve and restarted mysql but this didn't really change anything I am logging slow queries and none from server B are recorded in the file Running the same query from remote ssh connection from server B to server A's mysql is very fast Connection is set to persistent on server B's e-commerce Both server have centos 6.2 installed with WHM/Cpanel, configurations are basically the same. Do I miss something obvious? I've got my own proprietary framework. I call it Brain. It uses composer, and installation is done with a single composer file, which is handy. Here's an example:
{ "name": "skunkbad/brain-test", "description": "My Awesome App", "license": "proprietary", "minimum-stability": "dev", "repositories": [ { "type": "hg", "url": "ssh://hg@bitbucket.org/skunkbad/brain" } ], "require": { "skunkbad/brain": "default" }, "scripts": { "post-install-cmd": "Brain\\Statics\\BrainInstallScript::run" } }Brain has it's own dependencies, which aren't all really dependencies, but I've added them all to its composer.json file so I get everything I want for a new project. Here is it's composer.json: { "name": "skunkbad/brain", "version": "1.0.0", "type": "framework", "license": "Proprietary", "authors": [ { "name": "Robert B Gottier", "email": "xXxXxXxXx@gmail.com", "homepage": "http://brianswebdesign.com", "role": "Developer" } ], "require": { "pimple/pimple" : "v2.0.0", "swiftmailer/swiftmailer": "v5.2.0", "dompdf/dompdf" : "0.6.1", "phpseclib/phpseclib" : "0.3.6", "stripe/stripe-php" : "v1.15.0", "firephp/firephp-core" : "dev-master", "doctrine/dbal" : "v2.4.2" }, "autoload": { "psr-4": { "Brain\\": "/", "App\\": "../../../App/" }, "classmap": [ "Statics/" ] } }In Windows terminal, I can run composer install or composer install --prefer-dist, and it seems that especially when the doctrine packages are being downloaded or cloned (whatever it does), its super slow. Some of them hang for so long that occasionally the terminal will give me a message indicating a particular package timed out (5 mins). So I was wondering if this is just the norm. Feels like I'm on dial-up, but my internet connection is Verizon FiOS (fiber optic). Here is an example of the time-out message I get from Composer: Failed to download doctrine/common from source: The process "git clone --no-checkout "git://github.com/doctrine/common.git" "C:\XXXxxx" && cd /D "C:\XXXxxx" && git remote add composer "git://github.com/doctrine/common.git" && git fetch composer" exceeded the timeout of 300 seconds. I timed my install, and composer/common actually hung for about 7 mins. Total time was 9.5 mins. hi, when I made my website I thought it would be a good idea to put the information I'm outputting in a function so I could just call that function on a single template page. However, everytime I load a page on the server it loads all the static content first (ie, sidebar, logo, ect.) Then it loads the dynamic content. I'm okay with this, but it also doesn't add in the background until after it loads the dynamic content (which bothers me). Can I re-arrange my site's coding to prevent this? Thanks - charlie PS: my site is www.rushhunt.com hey friends i badly need one help i want to read some remote file say http://xyz.com/my.file when i download using wget in shell its reading with more than 4mbps but when i use fread/file_get_contents/curl function in php script its read with too slow speed please help me please |