Solved

OCIParse / OCIExecute > Multiple sign on's to ORCL?

Posted on 2006-11-29
8
360 Views
Last Modified: 2013-12-12
The PHP script below is having to sign on to the ORCL database every time it runs a query.  The sign on process takes several seconds each time causing the script execution time to run into minutes when it should be seconds.  How do I change this PHP script so that I only have to sign on to the database once?

$conn = OCILogon('username', 'password', 'database_name');
$query1 = "SELECT customer_id FROM table"
$run_query1=OCIParse($conn, $query1);
OCIExecute($run_query1);
while (OCIFetchInto($run_query1, $loop1, OCI_ASSOC)) {
     $query2 = "SELECT count(monkeys),count(bananas) FROM table WHERE customer_id =".$loop1['customer_id'];
     $run_query2=OCIParse($conn, $query2);
     OCIExecute($run_query2);
     while (OCIFetchInto($run_query2, $loop2, OCI_ASSOC)) {
          echo "The customer with Customer ID ".$loop1['customer_id']." has ".$loop2['monkeys']." monkeys and ".$loop2['bananas']." bananas";
     }
}
0
Comment
Question by:Geoff Millikan
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18039135
So, even though you create a connection handle ($conn) you still need to sign on every time? That's weird indeed.
Are you sure
$conn = OCILogon('username', 'password', 'database_name');
is only used once and that it's not in a loop?
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18039210
If this is not the problem, you might want to have a look at your php.ini and look for this directive:
oci8.max_persistent

If you set it to -1 it means there is no limit to the amount of persistent connections...
0
 

Author Comment

by:Geoff Millikan
ID: 18041514
Yes, I'm sure the $conn is not looped.  Good thought.

The more I think about this, I'm wondering if the the sign on actually takes place only in the "$conn" statement?  In otherwords, it only connects once and the reference to "$conn" in the OCIParse function only names the established connection to use?  That would make sense but would be nice to confirm it.  If this is true, then the issue is slow queries, not slow sign on.
 
I tried using "oci_pconnect" but do not see any performance gain.  oci8.max_persistent is set to -1 according to phpinfo().

http://us2.php.net/manual/en/function.ociparse.php

If you can confirm that the sign on only happens once, even though the OCIParse references the connection multiple times, then I'll assign you the points.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Geoff Millikan
ID: 18042369
FYI - I made two connections like this:

$conn1 = OCILogon('username', 'password', 'database_name');
$conn2 = oci_pconnect('username', 'password', 'database_name');

and then I ran the same query under each connection to see which one was faster.  The script run under OCILogon was faster by about 30%.

The amount of time to run both the $conn1 and $conn2 statements was 0.077306 seconds.
0
 
LVL 3

Expert Comment

by:nishayr
ID: 18042777
If you are looking for a significant performance boost, you might try using bind variables...

Thanks,
Nish
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 18043587
> The script run under OCILogon was faster by about 30%.
That might be a bit deceiving. If you run the same queries twice after one another, they are probably cached. That would explain the 30% increase in peformance.

Anyway, it looks like the queries themselves are slow. Your current setup selects customer ids from all customers and then you query the DB for each customer id. why don't you change that and drop the first query and adjust the second query like so:
$query2 = "SELECT customer_id, count(monkeys),count(bananas) FROM table GROUP BY customer_id;

And then use a while loop from that result set to print the data...
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now