I5_pconnect how can i re-use it?

General discussion on Zend Server for IBM System i
aaron-s-hawley
Posts: 46
Joined: Thu Mar 11, 2010 4:43 pm
Location: Colchester, VT
Contact:

Re: I5_pconnect how can i re-use it?

Post by aaron-s-hawley » Thu Feb 17, 2011 6:03 pm

marcoart wrote: ho can i re-use this open connection (i see into as400 that job is still alive) in as400 call??
why if i save into the $_SESSION the resource $conn ($conn = @i5_ponnect....) i see 0 value into this in second php page??
According to the PHP manual,

"It is currently impossible to register resource variables in a session. For example, you cannot create a connection to a database and store the connection id as a session variable and expect the connection to still be valid the next time the session is restored. PHP functions that return a resource are identified by having a return type of resource in their function definition. A list of functions that return resources are available in the resource types appendix."

from http://php.net/manual/en/function.session-register.php

The Zend Navigator demo application, simply stores the username and password in the session, and presumably runs i5_connect() on every request to the application.

Hope that helps,

darkluke980
Posts: 61
Joined: Sat Mar 28, 2009 8:31 pm
Location: Italy
Contact:

Re: I5_pconnect how can i re-use it?

Post by darkluke980 » Fri Feb 18, 2011 12:01 pm

Hi,

you can use I5_PRIVATE_CONNECTION and store connection in $_SESSION:

<?php

/* Private connection to i5/OS */

conId = 0;

if (isset($_SESSION['connectionID']))

{

$conId = $_SESSION['connectionID'];

echo "Connection ID is $conId<BR>";

}

else

{

echo "No connection ID stored.<BR>";

}

// I5_OPTIONS_PRIVATE_CONNECTION connection is private for the session

// I5_OPTIONS_IDLE_TIMEOUT After a delay with no activity, the job will end.

$retcon = i5_pconnect ('SYSTEMI', "USER", "pwd",

array(

I5_OPTIONS_PRIVATE_CONNECTION => $conId,

I5_OPTIONS_IDLE_TIMEOUT=>"60"));

if (is_bool($retcon) && $retcon == FALSE)

{

$errorTab = i5_error();

if ($errorTab['cat'] == 6 && $errorTab['num'] == -12){

echo "Connection ID no longer active<BR>";

$_SESSION['connectionID'] = 0;

} else

print_r($errorTab);

}

else

{

if ($conId == 0)

{

//Session varaible was 0: Get connection ID and store it in session variable.

$ret = i5_get_property(I5_PRIVATE_CONNECTION, $retcon);

if (is_bool($ret) && $ret == FALSE)

{

$errorTab = i5_error();

print_r($errorTab);

}

else

{

// Connection ID is stored in session variable

$_SESSION['connectionID'] = $ret;

}

}

}

?>

Bye

Luca

chris_hird
Posts: 171
Joined: Fri Apr 10, 2009 12:41 am
Location: Toronto
Contact:

Re: I5_pconnect how can i re-use it?

Post by chris_hird » Thu Feb 24, 2011 1:00 am

We use the same process Luca has described and store multiple connections to multiple systems. You can even pass the connection between functions which is a nice feature.

Chris...
Shield Advanced Solutions Ltd
Home of JobQGenie and the Receiver Apply Program
http://www.shield.on.ca/Blog

rcmartin
Posts: 15
Joined: Wed Jul 14, 2010 12:54 pm

Re: I5_pconnect how can i re-use it?

Post by rcmartin » Thu Feb 24, 2011 8:02 pm

As a follow-up to this post - I have been attempting to reuse an i5_pconnect() connection across web page requests (within the same browser instance, so same PHP session), with each connection attempt using the same host, user, pw and options... but every time I try, a new connection (job) is created.

Is there something else I should be checking for?

Any assistance welcomed!

darkluke980
Posts: 61
Joined: Sat Mar 28, 2009 8:31 pm
Location: Italy
Contact:

Re: I5_pconnect how can i re-use it?

Post by darkluke980 » Fri Feb 25, 2011 9:41 pm

Hi,

please, can you post your code?

Bye

marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Re: I5_pconnect how can i re-use it?

Post by marcoart » Thu Mar 03, 2011 1:14 pm

hi try with:

Code: Select all

		$conId = 0;
		$session = new Zend_Session_Namespace('connection');
		if (isset($session->connection)){
			$conId = $session->connection;
			$conn = @i5_pconnect($i5_server_ip, $i5_uname, $i5_pass,array(I5_OPTIONS_PRIVATE_CONNECTION => $conId,I5_OPTIONS_IDLE_TIMEOUT=>"6000",I5_OPTIONS_INITLIBL=>$libl));
			
		}else{
			$conn = @i5_pconnect($i5_server_ip, $i5_uname, $i5_pass,array(I5_OPTIONS_PRIVATE_CONNECTION => $conId,I5_OPTIONS_IDLE_TIMEOUT=>"6000",I5_OPTIONS_INITLIBL=>$libl));
			$ret = i5_get_property(I5_PRIVATE_CONNECTION, $conn);
			$session->connection = $ret;			
		 }
and i create a connet to as400 with $ret = 808832 (that is the same value that i see into as400)
now in the second php page i try to:

Code: Select all

$conId = $session->connection;
$conn = @i5_pconnect($i5_server_ip, $i5_uname, 
$i5_pass,array(I5_OPTIONS_PRIVATE_CONNECTION => $conId,I5_OPTIONS_IDLE_TIMEOUT=>"6000",I5_OPTIONS_INITLIBL=>$libl));
where $conId = 808832 (the 808832 into as400 is still active) but i receive an error:
808832 connection not found...

someone can help me?
thanks
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

darkluke980
Posts: 61
Joined: Sat Mar 28, 2009 8:31 pm
Location: Italy
Contact:

Re: I5_pconnect how can i re-use it?

Post by darkluke980 » Thu Mar 03, 2011 10:23 pm

Hi, user and password are the same?

The second page is called with ajax or include or require in the first page.

marcoart
Posts: 25
Joined: Thu Feb 17, 2011 12:09 pm
Location: Roma
Contact:

Re: I5_pconnect how can i re-use it?

Post by marcoart » Fri Mar 04, 2011 10:20 am

hi,

user and pwd are the same.
i at the moment i have 3 page:

test.php

Code: Select all

require_once("include/Auser.php");
$Auser = new Auser($user, $pwd);
$mess = $Auser->getErrorMes();

if($mess == ''){
 require_once("include/Buser.php");
 $Buser = new Buser($user, $pwd);
}
in Auser.php and Buser.php i have to access into as400 and check if the user is ok.

Now i think, that i have to re-use connection also in ajax call or in different part of my application, for example i need to do login in first page, than i want re-use this connection in every part of my application!

thanks!!
Best Regards
______________________________________________
Ristoranti Roma

e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it

darkluke980
Posts: 61
Joined: Sat Mar 28, 2009 8:31 pm
Location: Italy
Contact:

Re: I5_pconnect how can i re-use it?

Post by darkluke980 » Fri Mar 04, 2011 6:45 pm

Hello,

I think the problem is that two pages from the same instance of PHP can't open and then reopen the same connection.

Let me explain, in the the second page you should not make the connection because is already active.

The reuse of a connection is on the next "click".

Post Reply