Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Sab669 posted:

I'm not sure if this belongs in the PHP thread or the SQL thread, but I'm trying to work on an edit page for a list of users.


I've echoed out all of my variables before trying this, so I know they are being passed properly to the edit page, but it's not editing them. I think it's just a minor syntax issue that I'm not used to with web development, but I'm not sure. It just echoes out the Error from my or die statement.

e; Found this? http://www.freewebmasterhelp.com/tutorials/phpmysql/7 The Update section appears to be identical to how I'm trying to do it.

Please, for the love of all that is good and holy, don't pay any attention to anything that uses mysql_* functions to access databases if you don't need to.

PDO has been in PHP since 2004.

code:
$dsn = "mysql:host=localhost;port=3306;dbname=database";
$pdo_obj = new PDO($dsn, "username", "password", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$query = $pdo_obj->prepare("UPDATE users SET name_first =':fname', name_last= ':lname', 
 username=':uname', pwd = ':pwd', is_teacher =':teacher' WHERE ID = :id");

$query->bindValue(':fname', $fname);
$query->bindValue(':lname', $lname);
$query->bindValue(':uname', $username);
$query->bindValue(':pwd', $password);
$query->bindValue(':id', $id);

$query->execute();
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

It's a DB wrapper for PHP that sanitizes input inside bindValue/bindParam, and it's standard on most sane PHP installations. Please, don't go around writing your own db input sanitization if you don't absolutely have to.

(Also, having your variables external to the string and not having to gently caress around with string concatenation? Extremely nice.)

Ursine Catastrophe fucked around with this message at 20:10 on Oct 20, 2011

Adbot
ADBOT LOVES YOU

Null Set
Nov 5, 2007

the dog represents disdain

OriginalPseudonym posted:

Please, for the love of all that is good and holy, don't pay any attention to anything that uses mysql_* functions to access databases if you don't need to.

PDO has been in PHP since 2004.

code:
$dsn = "mysql:host=localhost;port=3306;dbname=database";
$pdo_obj = new PDO($dsn, "username", "password", array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$query = $pdo_obj->prepare("UPDATE users SET name_first =':fname', name_last= ':lname', 
 username=':uname', pwd = ':pwd', is_teacher =':teacher' WHERE ID = :id");

$query->bindValue(':fname', $fname);
$query->bindValue(':lname', $lname);
$query->bindValue(':uname', $username);
$query->bindValue(':pwd', $password);
$query->bindValue(':id', $id);

$query->execute();
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

It's a DB wrapper for PHP that sanitizes input inside bindValue/bindParam, and it's standard on most sane PHP installations. Please, don't go around writing your own db input sanitization if you don't absolutely have to.

(Also, having your variables external to the string and not having to gently caress around with string concatenation? Extremely nice.)

There is really no good reason not to do the above.

Aside:
You know you can pass an array of your parameters to execute(), instead of doing a bindValue for every one?

So instead of a long list of binds, you can do execute($query, array(':fname'=>'Original', ':lname'=>'Pseudonym')).

What I usually do for queries is to write a function that takes the query with parameters, and an array of parameters, then does a prepare($query) and execute($parameters), then return the PDOStatement. Then I just have to beat anyone with a 2x4 that doesn't use parameters.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Null Set posted:

There is really no good reason not to do the above.

Aside:
You know you can pass an array of your parameters to execute(), instead of doing a bindValue for every one?

So instead of a long list of binds, you can do execute($query, array(':fname'=>'Original', ':lname'=>'Pseudonym')).

What I usually do for queries is to write a function that takes the query with parameters, and an array of parameters, then does a prepare($query) and execute($parameters), then return the PDOStatement. Then I just have to beat anyone with a 2x4 that doesn't use parameters.

I'm aware of it, but I tend to keep it outside for a couple reasons.
1. It keeps it readable/easily modifiable. To my mind, having to go hunt through a line of array(':y' => 'y', ':z' => 'z', ... ) isn't a whole lot better than $querystring = "select * from something where x = " . $x . " and y = " . $y . " ...".

2. Kind of in line with one, but I like to bind my parameters at the point where I get the value for them, as opposed to having a block of binds right before I execute the query.

3 would be that there's a distinct difference between bindParam and bindValue, but I honestly haven't come across a situation where it's sane to bindParam before doing data modification, as opposed to bindValue after. Maybe one day...

But yeah, it's just personal preference. As for my typical use case, usually the first thing I'll do in any more-than-just-a-script project is write a quick base Model class and has children that correspond to any table I'm interacting with. Class variables that have a list of columns, then the actual update in this particular case would look more like:

code:
$user = User::loadById($id);
$user->params['fname'] = $fname;
$user->params{'lname'] = $lname;
$user->params['uname'] = $uname;

$user->save();

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Null Set posted:

You know you can pass an array of your parameters to execute(), instead of doing a bindValue for every one?

So instead of a long list of binds, you can do execute($query, array(':fname'=>'Original', ':lname'=>'Pseudonym')).

I don't like doing that, because it makes diffing changes a pain in the rear end. Yeah it's fewer lines, but it's sooo much easier to diff if they are all on separate lines.

Null Set
Nov 5, 2007

the dog represents disdain

fletcher posted:

I don't like doing that, because it makes diffing changes a pain in the rear end. Yeah it's fewer lines, but it's sooo much easier to diff if they are all on separate lines.

I usually give each element of the array its own line when there's more than one or two. Personally, I actually find it easier to read with all of the parameters bound at end.

I could see using bindParam to declare variables- since you're passing a reference, you wouldn't have to worry about the placement of bindValue to make sure you got the correct value. But if your code is structured sanely, that shouldn't be a big deal anyway. bindParam at the beginning vs bindValue right at the end probably comes down to personal preference.

bindValue as the values come up just seems to be asking for trouble, though. Easy to inadvertently make a change after the value is already bound and not notice it.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Null Set posted:

bindValue as the values come up just seems to be asking for trouble, though. Easy to inadvertently make a change after the value is already bound and not notice it.

To be fair. That said, my code is usually structured like:
code:

// Data calculation for variable soandso
$soandso = $_POST['soandso'];
do_random_shit_to($soandso);
$query->bindValue(':soandso', $soandso);

// Data calculation for variable foobar
$temp = $_POST['foobar'];
do_random_other_shit_to($foobar);
$query->bindValue(':foobar', $foobar);

/*
 * remove a couple dozen lines of other similar stuff
*/

$query->execute();
It's just easier for me personally to keep the logic for any given variable in one spot where it's sane/possible to do, full-array-foreaches notwithstanding. I can definitely see how it could bite me in the rear end if I wasn't used to it, though.

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players
What's the best way to make this work? I want argle::hurfdurf to echo "durf"

php:
<?
class bargle {
  const HURF = 'durf';
}

class argle {
  const OTHER_CLASS = 'bargle';

  public static function hurfdurf() {
    echo self::OTHER_CLASS::HURF;
  }
}
?>

mewse
May 2, 2006

is it important that OTHER_CLASS is const?

this works:

php:
<?php
class bargle {
  const HURF 'durf';
}

class argle {
  public static function hurfdurf() {
    $other_class "bargle";
    echo $other_class::HURF "\n";
  }
}

argle::hurfdurf();
?>

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

mewse posted:

is it important that OTHER_CLASS is const?

I'll probably do it that way, but I guess my question should have been if I could make it work by using curly braces or some other strange syntax.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Doctor rear end in a top hat posted:

What's the best way to make this work? I want argle::hurfdurf to echo "durf"

php:
<?
class bargle {
  const HURF = 'durf';
}

class argle {
  const OTHER_CLASS = 'bargle';

  public static function hurfdurf() {
    echo self::OTHER_CLASS::HURF;
  }
}
?>

echo constant(self::OTHER_CLASS . '::HURF') should work, but I don't have a CLI on hand to test it.

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

OriginalPseudonym posted:

echo constant(self::OTHER_CLASS . '::HURF') should work, but I don't have a CLI on hand to test it.

It does work!

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Doctor rear end in a top hat posted:

It does work!

Avatar makes post. But excellent :v:

stoops
Jun 11, 2001
i dunno php that well, and actually doing this from wordpress but i think this is more of a php question.

i have this code:

code:
<?php echo get_post_meta($post->ID, "mp3", true);?>
where "mp3" is a custom keyword in wordpress. when it executes, i get the string value.

now, this other code below makes an audio player out of any mp3 i input.

code:
<?php if (function_exists("insert_audio_player")) {  
  insert_audio_player("[audio:[url]http://www.domain.com/song.mp3[/url]]");  
} ?>
what i'm trying to do is replace everything inside [url] from the second piece of code to

<?php echo get_post_meta($post->ID, "mp3", true);?> from the first piece of code.

i'm having trouble and erroring out when putting php within php.

i appreciate any help.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm not completely clear on what those do and what you are trying to do with them, but I think you basically want string concatenation?

php:
<?
if (function_exists("insert_audio_player")) {
  insert_audio_player("[audio:[url]http://www.domain.com/".get_post_meta($post->ID, "mp3", true)."[/url]]");  
}
?>

stoops
Jun 11, 2001

fletcher posted:

I'm not completely clear on what those do and what you are trying to do with them, but I think you basically want string concatenation?

php:
<?
if (function_exists("insert_audio_player")) {
  insert_audio_player("[audio:[url]http://www.domain.com/".get_post_meta($post->ID, "mp3", true)."[/url]]");  
}
?>

sorry it was a bit confusing. i put in your code and it works somewhat, except it's outputting 2 players instead of one, but it still works. so thanks.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

stoops posted:

sorry it was a bit confusing. i put in your code and it works somewhat, except it's outputting 2 players instead of one, but it still works. so thanks.

It would help if you give us an example of what exactly get_post_meta is spitting out.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I'm sorry to do this to you guys; I'm not a PHP expert, but I've got a buddy who is in a bit of a bind. He's running a phpbb forum attached to a mySQL database (both on the same server). Recently, due to some successes in the business the forum is linked to, his user/post count has increased quite a lot. It's a relatively sensitive time for him and now he's getting these:

quote:

General Error
SQL ERROR [ mysql4 ]
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11) [2002]
An sql error occurred while fetching this page. Please contact an administrator if this problem persists.

However, they are intermittent, depending (apparently) on load. From what I can tell this isn't even necessarily phpbb specific, but instead seems roughly analogous to 'I have run out of <resource> and have now shat myself' for mySQL. He disabled some of the messaging/email notification style functionality in phpbb and that seems to have given him some breathing room, but it disappeared in less than an hour. I'd like to help, but I'm almost exclusively a windows guy now (haven't touched PHP since ver 3). I'm guessing this error is pretty common, and was wondering if there's anyone here who has past experience who can say something like 'oh, he's running phpbb and mysql and getting that error? It must mean you have to garflaxle the raffleassle!'.

In the absence of a magic bullet solution as above, I'd appreciate any guidance you guys might be able to provide to help troubleshoot the problem. Should I be looking at:
- phpbb's table structure/indexes in mySQL?
- phpbb's database connection/pooling/management code?
- mySQLs database health and resource use?
- Give up because this error too generic?

(and notes on how to do any of that would be welcome too). Server is remote and he only has cpanel and mysql query access.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
It's probably not an easily solvable thing. The manual says:

quote:

The error (2002) Can't connect to ... normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
I've never seen it before when using a socket file when MySQL was actually running.

Given the circumstances you've described, I'd expect too many connections, which is an entirely different error message and code.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Is he using shared hosting? What is the peak number of users the board is hitting?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

fletcher posted:

Is he using shared hosting? What is the peak number of users the board is hitting?

It's a dedicated standalone server, here's his board scrawl:
Total posts 26xxxx • Total topics 15xxx • Total members 4xxx.

I think most users ever (at once) was around 250, when this started happening.

McGlockenshire:
I'm pretty sure it's a resource issue and not a 'mySQL isn't running' issue since it's so intermittent.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Scaramouche posted:

It's a dedicated standalone server, here's his board scrawl:
Total posts 26xxxx • Total topics 15xxx • Total members 4xxx.

I think most users ever (at once) was around 250, when this started happening.

McGlockenshire:
I'm pretty sure it's a resource issue and not a 'mySQL isn't running' issue since it's so intermittent.

I would actually point him to this. While I haven't actually had the opportunity to apply it to one of the sites I'm helping with (server admin is a little protective and resistant to new ideas), it looks like it might be a legitimate place to start looking for issues.

The other question is "does the mysql error log have any obvious crap going on".

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Scaramouche posted:

It's a dedicated standalone server, here's his board scrawl:
Total posts 26xxxx • Total topics 15xxx • Total members 4xxx.

I think most users ever (at once) was around 250, when this started happening.

McGlockenshire:
I'm pretty sure it's a resource issue and not a 'mySQL isn't running' issue since it's so intermittent.

A modest dedicated server should be handle that load. In addition to what others have said, check out the slow query log.

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

How much RAM does he have and does he have a my.conf setup?

ryo
Jan 15, 2003
I want to be able to json_encode() an array of three strings, two of which contain a URL and/or HTML.
I want the output to just be
code:
{
    "value":"something"
    "label":"<some tag>data</some tag><br /><img src=\"http://url.com/image.png\">Some text"
    "url":"http://url.com"
}
except it's escaping URLs to make it look like http:\/\/url.com and escaping closed HTML tags like <\/some tag>. It is correctly escaping double-quotes though, which is what I want.

I noticed that there is a JSON_UNESCAPED_SLASHES option available in PHP 5.4 but we're on 5.3.3 and might not be able to update for a while.

Will I have to wait until we can update to 5.4 or is there another way round this? I know very little about JSON other than the general premise!

Dance The Mutation
Jul 27, 2011
I have a pretty dumb question related to PHP/mySQL. I'm new to the language and working on a site for a coworker. I was just curious how to handle data in a mySQL database that may or may not be empty. Do I use a null property for the column? When I check the database in PHP, do I use a basic boolean type conditional (if value == null)? Basically, he wants the site to display a message to the user if the user needs to do something. So if the user is on top of their stuff, there will be no message to display and that value in the table will be empty. If the user is not on top of their stuff, the value will be filled with a text message that needs to be displayed. I haven't really found an answer for how to do this and the book I'm reading said to avoid empty values in a database. Thanks for the help!

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Dance The Mutation posted:

I have a pretty dumb question related to PHP/mySQL. I'm new to the language and working on a site for a coworker. I was just curious how to handle data in a mySQL database that may or may not be empty.

There are two situations where you might commonly use nullable columns. The first is where a column is supposed to hold a value, but the rightful value to be stored might be unknown, e.g. the column is supposed to hold the height in inches of a person but the person has not supplied their height. The second is where the value to be stored in the column might not actually exist, e.g. the column is supposed to hold the date when someone last logged in to your website but they have never logged in, or it's supposed to hold the date they obtained their driver's license but they do not have one. In this case it is kind of a special "Not Applicable" value.

In general you use a nullable column where a column may have either one value, or no value at all. Using NULL is not a substitute for having a separate table if a separate table is what a normalised database design would call for. If the book you are using explains why the authors discourage NULL values then you may be able to reconcile their reasoning with my explanation; if it does not explain why then it is a bad book.

Dance The Mutation posted:

When I check the database in PHP, do I use a basic boolean type conditional (if value == null)?

Whether NULL values from the MySQL database are translated into PHP's null value really depends on how the database access method you are using is implemented. There are three notable ways your friend might be accessing his database. They are the mysql library (obsolete, but still gets used a lot because of outdated example code on the net that uses it), the mysqli library, and PDO. Mysqli uses PHP's null value to represent NULL values from the database. I do not know what the other two do.

I would use if (is_null(value)), I would not check == equality with null because type-juggling might result in nasty surprises.

Dance The Mutation
Jul 27, 2011

Hammerite posted:

:words:

Thanks for the fast reply. It seems like in my case then I would use a nullable column for this kind of data. Basically the data stored will be either of the situations you described. I will reread the section on the empty values and see if I can better understand the author's intent. I'm using this book which I like to think is a pretty legitimate book... Thanks again!

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

Hammerite posted:

They are the mysql library (obsolete, but still gets used a lot because of outdated example code on the net that uses it), the mysqli library, and PDO. Mysqli uses PHP's null value to represent NULL values from the database. I do not know what the other two do.

PDO does this as well. It's nice.

Dance The Mutation
Jul 27, 2011
Another really dumb question that I can't seem to find a specific answer on the web. In regards to variable scope, I understand the whole using variables inside of functions and outside and all that but what about separate php calls in one html document? For example at the top of my document I have

code:
<?php 
session_start();
$user = $_SESSION['myusername'];
include("functions.php");
?>
and later on I have the code where I act on the information that pertains to that user. I'm specifically asking in the context of session management but I want to understand how/why this works. My $user variable is used fine later on in the document when I do the mySQL queries with that variable.

Ursine Catastrophe
Nov 9, 2009

It's a lovely morning in the void and you are a horrible lady-in-waiting.



don't ask how i know

Dinosaur Gum

Dance The Mutation posted:

Another really dumb question that I can't seem to find a specific answer on the web. In regards to variable scope, I understand the whole using variables inside of functions and outside and all that but what about separate php calls in one html document? For example at the top of my document I have

code:
<?php 
session_start();
$user = $_SESSION['myusername'];
include("functions.php");
?>
and later on I have the code where I act on the information that pertains to that user. I'm specifically asking in the context of session management but I want to understand how/why this works. My $user variable is used fine later on in the document when I do the mySQL queries with that variable.

Every page is it's own scope. It helps if you think about it in terms of:
code:

<?php
session_start();
$user = $_SESSION['myusername'];
include("functions.php");

echo "HTML CODE HERE";

echo "Welcome, $user!";
?>
This is also the case in terms of any included files-- for example, you could legitimately use the $user variable inside of functions.php and it'll have the value of $_SESSION['myusername']. It's only inside of actual blocks that the variable scope changes, and php opening/closing tags don't count as moving out of your current block.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Dance The Mutation posted:

Another really dumb question that I can't seem to find a specific answer on the web. In regards to variable scope, I understand the whole using variables inside of functions and outside and all that but what about separate php calls in one html document? For example at the top of my document I have

code:
<?php 
session_start();
$user = $_SESSION['myusername'];
include("functions.php");
?>
and later on I have the code where I act on the information that pertains to that user. I'm specifically asking in the context of session management but I want to understand how/why this works. My $user variable is used fine later on in the document when I do the mySQL queries with that variable.

The following two snippets of code are equivalent. They do EXACTLY the same thing. (Assume that prior to the start of the snippet, the parser is within a block of PHP.)

code:
?>

Some arbitrary text

<?php
code:
echo '

Some arbitrary text

';

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I've set up a local Windows development environment, and some of the code is going much slower than in Linux. Now, part of this might be the database connection time - before, it was on the same machine as the MySQL server, whereas now it's 200 miles away - but I'm not sure that accounts for some of the massive slowness I'm seeing. Are there any functions that are known to be slower in Windows than in Linux?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Hey guys, just wanted to let you know I wasn't ignoring your responses to my question, it's just that my friend dropped off the face of the earth (he's got a big deadline) and since I don't have access to the server at the moment there's not much else I can do! Thanks for the info provided so far, he should be sane again later this week and we can hopefully get it sorted then.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Golbez posted:

I've set up a local Windows development environment, and some of the code is going much slower than in Linux. Now, part of this might be the database connection time - before, it was on the same machine as the MySQL server, whereas now it's 200 miles away - but I'm not sure that accounts for some of the massive slowness I'm seeing. Are there any functions that are known to be slower in Windows than in Linux?

Anything cryptography-related can be dramatically slower in Windows due to how OpenSSL (doesn't) use Windows' built in crypto facilities.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

McGlockenshire posted:

Anything cryptography-related can be dramatically slower in Windows due to how OpenSSL (doesn't) use Windows' built in crypto facilities.

mcrypt is used but only a few times... but after switching the database to use the local read-only one instead of the main one 200 miles away, it sped up to almost usable speeds. In other words, it's the connection lag. Which means 1) I have to still test on the remote server, and 2) I really need to make this thing more efficient, because being local to the database is allowing for inefficiencies. (To give an example: This one action involves somewhere around *6400 queries*. On the server where it's local to the database, this takes a couple of seconds. But my poor machine 200 miles away is choking on the connections.)

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
On an entirely different topic: Now that 5.4 is starting to appear, does anyone know if it does, or is planned to, support dereferencing functions?

e.g. echo function_that_returns_array()['foo'];?

Edit: If only I searched the release notes, I would have found "Added array dereferencing support. (Felipe)" :holy:

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Golbez posted:

mcrypt is used but only a few times... but after switching the database to use the local read-only one instead of the main one 200 miles away, it sped up to almost usable speeds. In other words, it's the connection lag. Which means 1) I have to still test on the remote server, and 2) I really need to make this thing more efficient, because being local to the database is allowing for inefficiencies. (To give an example: This one action involves somewhere around *6400 queries*. On the server where it's local to the database, this takes a couple of seconds. But my poor machine 200 miles away is choking on the connections.)

6400 queries?? What the heck is it doing?

mewse
May 2, 2006

fletcher posted:

6400 queries?? What the heck is it doing?

Seriously. I was going to respond to the earlier post saying to ping the remote server and then multiply the milliseconds by the number of queries the script is performing in sequence, but then I didn't because it would have been a pretty glib response

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

fletcher posted:

6400 queries?? What the heck is it doing?

Loops through a query that returns 200 results and performs 25-35 queries on them. It could be cut down to either 200 queries (store the results from the first query in objects, which long-time posters here will know my predecessor was strongly against for some reason) or 1 query (it's just to check a flag in these, it's a complicated flag but it could potentially be stuffed into one ginormous query).

I never noticed before because, since the PHP and MySQL servers are on the same machine, the cost in connecting 6400 times was nonexistent.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Sounds like you should head over to the database questions thread and find out how to query that data more efficiently. Maybe you can get away with such a horribly inefficient solution in this scenario, but you should learn how to do it The Right Way for when you don't have that luxury.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply