Connection Pooling And Persistent Connections
http://php.net/function.mysql-pconnect
http://php.net/manual/en/featur...connections.php
Can one seriously see persistent connections as a form of db
connection pooling? Is it really similar?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Connection Pooling In PHP ?
I apologize if any of my questions appear daft or obvious ... Does PHP (or maybe the web server - Apache in my case), support (database) connection pooling?. It seems terribly inefficient if every request for data wil incurr the overhead of creating a connection to the db. While on the subject of pooling - does any one know (when using PHP in "server side scripting") if scripts are launched as seperate processes or if they are spawned as threads in a thread pool of a master process? (pref the latter since it is less "expensive" in computer resource terms)
Mysql Connection Pooling
In my environment, I have two servers. Server A is hosting PHP while server B is hosting Mysql. Both servers are on the same LAN. I noticed that my PHP page takes foreever to load. It turns out that the MySql connection call takes almost one second to return. This is all based on my TCP trace. To make matter worse, PHP is not reusing these MySql connection in other PHP pages, so the overall latency is pretty bad going from one page to another. I was wondering if anyone has any insight on why it takes so long to connect to Mysql server, and if there is a way to use connection pooling.
Persistent Connections
I just started coding with PHP a few days ago. My code interfaces with a simple database of the books I own. MySQL is running on my computer, and Apache/PHP is running on another. I tried using persistent connections to lessen the overhead of opening the TCP connection etc, but when I reload the page multiple times, PHP seems to make a new connection for each reload. I checked the processlist in MySQL and I had a whole bunch of sleeping connections from the webserver. So my question is... did I do something wrong? I basically just changed from connect to pconnect... and to test it I was just reloading the page, so it was using the same username and password for the database. Also, another question... how do I turn on compression when connecting to MySQL from a .php file? I don't have root access to the Apache machine.
Mysql_pconnect() Do Persistent Connections Ever Die?
I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an existing unused connection. If my system was to go through a busy period whereby I seen an extra 50% or more activity for ten minutes or so, would the extra connections stay alive for ever or is there a time limit of inactivity? Would the unused connections just sleep if they don't die? Is there any negative effect of having these connections waiting around? -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet?
Persistent Postgres Connections In PHP
Hello all! I'm working on a PHP site using Postgres as a back-end. I have an include at the top of each page that runs the pg_connect function. I'm implementing some temporary tables, which I understand are destroyed automatically at the end of the session. It seems to me that when I navigate to a new page, or re-load my existing page, I lose my temporary tables. Is this because I am creating a new session at the beginning of each page with my pg_connect include? Also, are temporary tables globally visible, or only within that session? I mean, can one user see another user's temporary tables?
Persistent Connections And Temporary Tables?
I'm having a heck of time understanding the way a few things work, or at least, the proper way to do them. To start off, I have a mysql 5 database that's loaded up with lots of stored procedures I've written for handling a firewall log table. When I started on my project, I didn't worry about things like multiuser ability, or pagination. Now that I've got a lot of the backend work done, I'm trying to improve the front end. My stored procs return their results in the form of a temporary table (engine=memory); as I understand the mysql documentation, a temporary table stored in memory exists only while the database connection is open, and is discarded once the connection closes. So that started me on a quest to maintain my connection to the database persistently across multiple page loads. This is were I start pulling my hair out. First I find that some group of developers in their infinite wisdom have decided to not support persistent connections in the mysqli (mysql improved) functions, to that end, there is no mysqli_pconnect function. I've tried mysql_pconnect, but the (old fashioned) mysql functions don't understand stored procedures, and I get an error back from mysql that the result cannot be represented (or something like that). So I started searching for alternatives. At first, I considered switching to postgres instead of mysql; pg offers sprocs and the php functions for it offer persistent connections. Rather than go the route of reconfiguring everything, I kept searching. I then came across the php odbc functions. They seemed pretty straight forward, and functionally similar to the mysqli functions. So, I installed an odbc connector on my server, and changed my code to use odbc instead of mysqli. Now I have odbc working correctly, the same way mysqli did previously. So now, I want to try to maintain a persistent connection. According to the php docs, I need to call odbc_pconnect first to setup the connection, and then when I want to re-use that connection, I can call it again with the same dsn, username and password. So lets say I visit index.php, which asks for a username and password, and then opens a connection to the database via odbc. I store the username and password in a session variable, which is subsequently checked by an include in all my other pages. The include grabs the u/p from the session array, and fires off another odbc_pconnect, presumably to reopen the db connection. So far so good; its all working. Now I decide to test if my db connection is actually being maintained, or just recreated. I fire off a stored proc using odbc_exec($link_id,"CALL mydb.myproc()") , followed by a query to grab results from the temporary table using odbc_exec again. This works as expected. However, in my code, I also set a session variable to indicate the sp has been run, so when I refresh the page, the sp will not be called, just the query on the temp table. This is where it breaks down. QuoteWarning: odbc_exec() [function.odbc-exec]: SQL error: [unixODBC][MySQL][ODBC 5.1 Driver][mysqld-5.0.22]Table 'ulogdb.summary_results' doesn't exist, SQL state S0002 in SQLExecDirect in /var/www/html/db/new_summary2.php on line 29 The table summary_results should still be there if my db connection had been preserved, however, it seems the db connection was closed somewhere along the way, and mysql destroyed the table. On a side note, odbc_pconnect causes apache to segfault if it passes an incorrect username or password to the odbc connector. Code:
Sessions And Persistent Connections To MySQL Database
PHP/MySQL and I've heard about maintaining a persistent connection to the database. To save overhead, I'd like to maintain the connection in a session variable, but I have a few questions first. I'm able to establish session variables and test them with isset() to avoid re-defining them with each new web-page load. So is this really as simple as if (!isset($_SESSION['connection'])) { $connection = mysql_connect("SomeServer","UserName","password"); $_SESSION['connection'] = $connection; }; Will this work? and is there a better way to do it--or a more conventional way? What should I be thinking about vis a vis security regarding this connection. Is there a recommended way to make the session's connection variable "expire"? I suppose I could store the time the connection was established and then check the elapsed time with each web-page re-load, dumping the session if it's been too long. Is there a preferred way to store $connection without using $_SESSION[]?
Persistent Connection
For each page on my site I have to open a database connection to retrieve data. I have only one database. For this specific situation do you think is better to use a persitent connection (mysql_pconnect) instead of mysql_connect?
Persistent, "keep-alive" Connections (or Such)
I'm looking for a way to create a PHP page that "stays alive" and updates (lines are added to the end) when other scripts make requests. I know this can be done, I've seen it work on some "on-line chat" sites, but can't figure out how to do it.
Persistent Variables
I have this variable that is passed in the the $_GET, which I then assign it to a $_SESSION variable to ensure persistency, however every time i reload the page the $_SESSION variable gets lost. Hence unusable. $_SESSION ['very'] = $_GET['pery']; How can I ensure persistency beyond page reloads?
Persistent Logins With Cookies
I am trying to make a persistent login like you find at yahoo and livejournal. i have basic knowledge about cookies. i am thinking to store the username and password as a cookie, with setcookie(). the problem is that there is an expiration date on the cookie. what is a way that i can work around the expiration date so that it is forever? i know some sites do something with ip's? what if the ip is not static?
Persistent Object Sessions
I have a that page opens an imap connection; I need to refer to the connection across various pages. I don't want to reopen that connection on every page (vast waste of resources). I have tried using sessions but they do not persist objects across pages the php manual says that too. I have searched all websites/forums and nobody seems to bring up/encounter this type of problem.(refer it, if i missed) I am used to asp where we could share a connection/object across pages in the same website or even across websites on the same server. I know the work around's:- 1) Reopen the connection on eve page --waste of resources 2) Save it to a database or file -- to much/complex maintenance work for something simple. Am I missing/not understood a feature in PHP4 or is it missing this?
Persistent Global Variable?
Are there something like a `Persistent global variable` in PHP? It is something like `Application` in the classic ASP, all the request share the same variable, and the die after a timeout.
Persistent Form Info
I have some forms that have different parts, and it decides which parts to display through the url ie form.php?showpart=1, showpart=2, etc. If I want to show another part and change the url all the form info goes away. I'm a self taught PHP guy, I'm decent but not amazing. My current solution is to use AJAX to write/modify a cookie everytime the user writes something and bring that in when they change the page. Is there an easier way?
Persistent Form Data?
I've set up a form with captcha and if someone enters the wrong captcha info and returns to the form to fix it, the previously filled in data is wiped out. What do I need to add so that the information persists? Would it be a session or cookie or ?
[pear] Persistent Parameter With HTML_QuickForm_Page
I am learning HTML_QuickForm_Controller pear extension. situation: In my project the pages are called by a op get parameter (index.php?op=foobar) and this needs to remain there even when forms are submitted. the problem: Unfortunately the attribute "action" of the html tag "form" is always "index.php", instead of "index.php?op=foobar". I have tried to pass "index.php?op=foobar" to the constructor of HTML_QuickForm_Page, with no results. It is still "index.php" (_self). When I worked only with QuickForm (with no controller) i used to set a hidden parameter "op" in the form and then handling it with a $_REQUEST instead of a $_GET. But now, with HTML_QuickForm_Controller, after the form data have been submitted the page refreshes (via http headers) and preserves no informations about the "op" parameter, so I get allways in the home page. Do you have any suggestion about modifying the action attribute of QuickForm_Page in a clean way (or even a working workaround)?
Temporary Tables (MySQL) With Persistent Databasse Con
I'm having this odd odd problem with temporary tables with a persistent database connection. I'm making this multi-page form/wizard type thing that store interim user data in an temporary table as follows: PHP Code:
Storing Huge Structure Persistent Or Alternative
I've got the following problem: I have a huge xml-file that represents a street map of a city. Each street is stored as a couple of coordinates (start, end and all the turns). When I set a marker in a google map, I want to find all streets that are near this marker position. I now parse the whole file as a simpleXML object, and calculate the distances to each street segment (using linear algebra algorithms, that is, constructing the vector from two points and computing the distance from the given point to this vector). Up to now it works like this: I set a marker and the gmaps method "gdownload()" calls a server side php script, which 1. reads the xml file into an simplexml object 2. for every two coordinates that belong to the same street, it calculates the vector and computes its distance to the point 3. returns the nearest x streets (as polylines) back to the client It repeats this, when I set the next marker. Problems/need for ideas: 1) It always reads the XML file anew, when I set another marker. Is there some way to cache this or a more intelligent approach? I tried saving the whole Simplexml-object in a session variable, but it was too huge. I guess I could create some tables in mysql, but I'm not sure thats the best solution yet. 2) Not php-specific: Do you have any ideas how to speed up the process of finding the nearest lane(s)? I tried to consider only those streets whose endpoints are within a certain range from the given marker- point, but it was not considerably faster and if there was a street thats very long and straight the endpoints may be far away, but the street itself is quite near.
Warning: Unknown Persistent List Entry Type In Module Shutdown (11)
I am getting this wanrning: Warning: Unknown persistent list entry type in module shutdown (11) in Unknown on line 0 I have never seen it before or know what it means and line 0 is hard to find especially when no document is specified Everything works as it should at this point just getting that warning on my personal apache server any ideas?
DB Connection Handling - I Get "too Many Connection" - What's The Solution?
I have a php-webpage that needs the database in the beginning and in the end of the script. In the middle there is a lot of processing that takes several seconds - during that time I don't use the database connection. What is the best approach? Should I close the connection after I'm done with it OR should I reuse the connection thru my whole script? Where can I read more about this? Any pointers? Today I'm using the same connection thru my script. And sometimes I get an error from the database "too many connections". What does that mean? My webserver provider says that I have at least 100 connections to play with. How come I get this error?
Too Many Connections
about twice a day, i've been getting DB errors for too many connections. can someone walk me through how to change this value? the mysql info on it is pretty mimimal. i'm on cpanel/WHM and have SSH access to my box.
Too Many Connections
I recently started to get an error-message 'Too many connections' when connected to a MySQL database. As I was the only person connected at the time, to a private development area, I suspect that it is because my pages are opening persistent connections, which aren't being closed for some reason. How can I stop this happening ? Here is my connection string: $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
How Many Connections Can You Have ?
Currently, I need to connect to 4 different databases on one page to extract information. But 1 of the 4 connections isnt working, is there a limit of 3 connections or something?
Php & Postgre Connections
I know this sounds a bit backwards, but i've got to port some scripts from mysql to postgre, but at the moment i don't have a postgre setup i can test on, sooooo can anyone tell me if this is the right way to connect..... $Connx_Id = pg_connect($Host_Name, $Port, , , $DBName); or is it..... $Connx_Id = pg_connect(host='$Host_Name', port='$Port', dbname='$DBName'); Also does postgre require a port or does it default to a standard if not specified like mysql defaults to 3306?
Closing Connections?
I know alot of people are probably getting tired of the mysq_(p)connect questions, but I could not find an answer anywhere else. If I run multiple queries in a page and parse HTML inbetween them, should I close the connections inbetween the queries (using mysql_connect()) or should I just let it be until the script is finished?
PHP Database Connections
I am trying to develop a web site on a development machine that needs to access data in a mysql database. I have mysql running on my development machine with a copy of the database. While developing the app. I can connect to the local version of the database without problems. Once I upload the database to its host site I need to change the php scripts that connect to the database to refelect the appropriate connection associated with the hosting server. Does anyone know of an efficient way to have my script test for which location it is on and connect to the appropriate mysql database? Or, does anyone know of a php script that can handle this programmatically?
Too Many MySQL Connections!
I had the "Too many MySQL connections" error on a page that is password protected to 150 users, and it uses one simple table and a simple SELECT * FROM table. The site wasn't launched or noticed, so all 150 users can't hit it at the same time. What can cause this upsetting error?
Two Mysql Connections
Not really tried going two ways at once, but I have an include_once connection to a mysql_database, now I need to retrieve info from a second mysql_database .. My mysql_connects are getting confused. So, (I've had a couple of beers), am I opening up too many at once? I'll look again in the morning, but am thinking that it is a bad idea to leave two connections open all the time ...
Too Many Connections To PostgreSQL
I'm running into a problem wherein I'm unable to connect to my postgresql db because the maximum number of connections has been reached. I use ADOdb for my db work, and the thing is I'm using the PConnect function, so it's supposed to be using persistent connections. Since this is the case, I find it very strange that I'm having problems with the number of connections to postgresql. Also, I'm the only one using Postgresql on this server (a test machine) and I'm working on one area of my project (two or three pages) so it should definitely be reusing the connections.
MS SQL Server Connections
I have Red Hat 9. Anyone here have that too and can help me? Without having to do a lot of major surgery, such as recompiling my PHP (which I consider risky), I want to use either unixODBC or FreeTDS to connect RH9 Linux to MS SQL Server 2000. I noticed from phpinfo() that FreeTDS wasn't configured into the PHP install, although I have installed FreeTDS just now. That's probably why the mssql_connect() call won't connect -- says Call to undefined function. I probably need to recompile PHP (again, risky) in order to get this to work. However, I *DID* notice that unixODBC was enabled, so I wanted to connect with that using this code: $dsn = "Driver={SQL Server};Server=10.22.109.5;Database=pubs"; $user = 'sa' $pass = 'password' $link = odbc_cconnect($dsn, $user, $pass); $sql = 'SELECT * FROM authors' $q = odbc_exec($link, $sql); $rec = odbc_fetch_array($q); echo $rec['au_lname']; odbc_free_result($q);
Mysqli Connections And Oop
If you do a page reload with $_SERVER['PHP_SELF'] will your program lose a mysqli connection upon the reload of the page? Would this code work? I need to know how to carry over a connection between methods as I am new to OOP? Thanks... Example; ======================================== <?php // webpage $newsignon = new newuser(); logon(); if (isset($_POST['submit'])){ $newsignon = query("SELECT name, password FROM database"); } ?> <?php // class newuser class newuser { public $name; private $passwd; private $mysqli; function __construct(){ include('dbconn.php'); $mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname); if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); exit; } $this->mysqli = $mysqli; // is this right? } //end constructor function query($query){ if ($result = $this->mysqli->real_query($query)){ $result = $this->mysqli->store_result(); if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";} } // end if } // end function function logon(){ echo "<form action='".$_POST['PHP_SELF']."' method='post' >"; // Would this work? echo "<input type='text' name='user' /><br /><input type='password' name='passwd' />"; echo "<input type='submit' value='submit' />"; } // end function } //end class
Mysql_pconnect(): Too Many Connections
I have been having my php scripts run into this error: mysql_pconnect(): Too many connections... And basically MySQL craps out. I have never run into this problem before, can anyone point me to where I might figure out how to fix it? Is it bad code? Am I supposed to be releasing connections somehow? Os should I only be using the none persistent connection "mysql_connect", that might be the trouble. Not sure why I am using mysql_pconnect now that I think about it.
Socket Connections With PHP
At the moment I have written a Temperature Server (takes readings from serial ports). Now I have a socket connection open on this server that receives client connections which either INSERT or VIEW. Now, I want to be able to connect to this server and input "view " and capture the output. I was wondering if someone could give me a good example of this in action or a good website about this.
PHP & Open Connections
I'd like to create a simple chat application that will leave the connection open for a minute and then restart the connection to the server to push data. I plan to use temporary .txt files to store messages. My question is how can I do that in PHP 5, what techniques should I do server-side to keep this connection open and how would be the flow of the message? Do I need a different technology such as Python to handle messages? 1. User A sends a message to the server 2. ? 3. User B receives the message instantly through an open connection
About Database Connections
I want to ask questions regarding database connections. See, if my mysql db is situated on one server which have php and mysql installed and i want to connect this db on a second server or say another server and execute the php script on that second server. How should I do this?
2 MySQL Connections
There's a database which stores various applications and a separate database (different connection) that stores forum information. These are tied together through a userid column. I need to have a forum rank posted along with the application list, and was wondering if it's possible to have 2 active connections. Essentially, while the rows are fetched from the database, it can pull one bit of info from the other. Is this possible or do I need to recode and merge the databases?
Database Connections
I am designing a web site for a housing company. They have a database (I believe it's MS SQL) that contains information regarding vacancies of their units which I would like to pull and display on the site. So my question is: is it possible to have the web site hosted by arbitrary company x, on their server, and connect to our server's database through php? Every example I have seen, it looks to me like the php scripts are being run on the same server as the database (or maybe I'm just missing something). If it is possible, could somebody point me in the direction of some sources and/or some sample code.
Mysql Connections With Authentication
Maybe this is a foolish request but I am a newbie to all of this. I have a private members site with all pages protected using the below script and it works very well. I also have a quick and dirty (dreamweaver coded) page that displays my online music,both need a connection to a mysql database, same database but different tables. My problem is and no doubt the experts here will already have guessed both codes will not exist on same page, is there a way around this?, if so please help me. and yes my code maybe messy but I am trying to learn. I have included samples below. $connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD); Script to protect member pages <? if (!class_exists (auth)) { include ("../auth.php"); } include ("../authconfig.php"); include ("../check.php"); if ($check["level"] != 6) { header('Location: ../no_access.php'); exit(); } ?> Connection for Music page $music = mysql_pconnect($hostname_music, $username_music, $password_music) or die(mysql_error()); Music page opening script <?php require_once('../Connections/music.php'); ?> <?php $currentPage = $HTTP_SERVER_VARS["PHP_SELF"]; $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) { $pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_music, $music); $query_Recordset1 = "SELECT title, artist, link, server FROM music ORDER BY title ASC"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $music) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) { $totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) { $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . implode("&", $newParams); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?>
Problem With Multiple Connections....
I'm running a website which connects to one database. Now I'm attempting to add code that will show the latest posts in the forum. The problem is that the forum is on a different database ( same localhost) different user and I have to open separate connection. I'm using link_identifiers, however still get some errors. $db2 = mysql_connect ("localhost", "username", "pass"); if ($db2 == false){ echo mysql_errno().":Ooops Error! ".mysql_error()."<BR>"; exit; } $b_forum = 1; $result_ib = mysql_db_query ("db_forum","select topic_title,forum_id, topic_lastp_n, topic_posts from forum_topics order by topic_id desc limit 15",$db2); while(list($Ib_topic_title,$Ib_forum_id,$Ib_topic_lastp_n,$Ib_topic_posts) = mysql_fetch_array($result_ib)) { // output to a variable $content.= "<font size=2><a href=http://somesite.com/forum/ikonboard.cgi?s=3c904c322dcfffff;act=SF;f=$Ib_forum_id><b>$Ib_topic_title</b> - $Ib_topic_posts replies</a></font><br>-<font size=2><tiny>posted by $Ib_topic_lastp_n </font><br><br>"; $b_forum++; }; mysql_close($db2);
Fsockopen() And Secure/SSL Connections?
Okay, this is probably a silly question, but I'm wondering if it's actually possible to obtain a secure HTTP form Post via fsockopen()? I know that I can pass post data via the function and it's headers.. however, my situation requires that the connection be secure. As I would be passing POST data to a merchant gateway server.
Multiple Simultaneous Connections
I am developing a metasearch script where search results are "screen-scraped" from different search engines via the fsockopen() function. But I have to go through each stream one by one, which greatly increases the script execution time. Is it possible to have a multi-threaded connection to different sites simultaneously? I assume the larger metasearch engines do this, but I'm not sure if any of them are coded in php.
Multiple Mysql Connections To The Same Db?
I know from reading on php.net that there is a boolean value you can set in mysql_connect() so that it will create a new link each time, even with the same arguments. But how do you specify which connection to use in your mysql_query (s)? PHP Code:
Question About Database Connections
My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50 visitors to my Web site can access my database through my Web site at one time? Or does this mean that in my code I can only use 50 connections? and like have an identifier for each connection, like if I used persistant connections?
OLEDB Connections To Access
Currently I use ODBC connections to Access databases on the IIS server I use. However I need to access a remote Access database on my domain but ODBC will not connect to. I have been told that I need to use the OLEDB connector instead but does this mean that I now need to replace my ODBC functions with the OLEDB equivelant and if that is true, then what are the OLEDB equivelants?
Mysql_pconnect Too Many Connections ERROR
I get this error mysql_pconnect Too many connections ... every now and then. Does anyone knows where it comes from ? There are a lot of sites running on the server and all of them use the Database frequently. Is there any configuration that I will have to do to my server in order to handle the load ?
|