?
Solved

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

Posted on 2006-11-29
8
Medium Priority
?
377 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
6 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 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