Page 1 of 2

I5_pconnect how can i re-use it?

Posted: Thu Feb 17, 2011 1:57 pm
by marcoart
hi guys!

i've a login panel where i log-in into as400 with user and pass using i5_pconnect.
Now, if the login-in is successful i pass to another php page where i have to do a call to RPG program.

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

thanks a lots.

Re: I5_pconnect how can i re-use it?

Posted: Thu Feb 17, 2011 6:03 pm
by aaron-s-hawley
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,

Re: I5_pconnect how can i re-use it?

Posted: Fri Feb 18, 2011 12:01 pm
by darkluke980
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

Re: I5_pconnect how can i re-use it?

Posted: Thu Feb 24, 2011 1:00 am
by chris_hird
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...

Re: I5_pconnect how can i re-use it?

Posted: Thu Feb 24, 2011 8:02 pm
by rcmartin
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!

Re: I5_pconnect how can i re-use it?

Posted: Fri Feb 25, 2011 9:41 pm
by darkluke980
Hi,

please, can you post your code?

Bye

Re: I5_pconnect how can i re-use it?

Posted: Thu Mar 03, 2011 1:14 pm
by marcoart
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

Re: I5_pconnect how can i re-use it?

Posted: Thu Mar 03, 2011 10:23 pm
by darkluke980
Hi, user and password are the same?

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

Re: I5_pconnect how can i re-use it?

Posted: Fri Mar 04, 2011 10:20 am
by marcoart
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!!

Re: I5_pconnect how can i re-use it?

Posted: Fri Mar 04, 2011 6:45 pm
by darkluke980
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".