I5_pconnect how can i re-use it?
I5_pconnect how can i re-use it?
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.
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.
Best Regards
______________________________________________
Ristoranti Roma
e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it
______________________________________________
Ristoranti Roma
e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it
-
- Posts: 46
- Joined: Thu Mar 11, 2010 4:43 pm
- Location: Colchester, VT
- Contact:
Re: I5_pconnect how can i re-use it?
According to the PHP manual,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??
"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,
-
- Posts: 61
- Joined: Sat Mar 28, 2009 8:31 pm
- Location: Italy
- Contact:
Re: I5_pconnect how can i re-use it?
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
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
-
- Posts: 171
- Joined: Fri Apr 10, 2009 12:41 am
- Location: Toronto
- Contact:
Re: I5_pconnect how can i re-use it?
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...
Chris...
Shield Advanced Solutions Ltd
Home of JobQGenie and the Receiver Apply Program
http://www.shield.on.ca/Blog
Home of JobQGenie and the Receiver Apply Program
http://www.shield.on.ca/Blog
Re: I5_pconnect how can i re-use it?
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!
Is there something else I should be checking for?
Any assistance welcomed!
-
- Posts: 61
- Joined: Sat Mar 28, 2009 8:31 pm
- Location: Italy
- Contact:
Re: I5_pconnect how can i re-use it?
Hi,
please, can you post your code?
Bye
please, can you post your code?
Bye
Re: I5_pconnect how can i re-use it?
hi try with:
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:
where $conId = 808832 (the 808832 into as400 is still active) but i receive an error:
808832 connection not found...
someone can help me?
thanks
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;
}
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));
808832 connection not found...
someone can help me?
thanks
Best Regards
______________________________________________
Ristoranti Roma
e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it
______________________________________________
Ristoranti Roma
e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it
-
- Posts: 61
- Joined: Sat Mar 28, 2009 8:31 pm
- Location: Italy
- Contact:
Re: I5_pconnect how can i re-use it?
Hi, user and password are the same?
The second page is called with ajax or include or require in the first page.
The second page is called with ajax or include or require in the first page.
Re: I5_pconnect how can i re-use it?
hi,
user and pwd are the same.
i at the moment i have 3 page:
test.php
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!!
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);
}
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
______________________________________________
Ristoranti Roma
e-mail: info@ristorantiromaristo.it
http://www.ristorantiromaristo.it
-
- Posts: 61
- Joined: Sat Mar 28, 2009 8:31 pm
- Location: Italy
- Contact:
Re: I5_pconnect how can i re-use it?
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".
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".