gkralik / php7-sapnwrfc

SAP NW RFC SDK extension for PHP 7.3+ & PHP 8
https://gkralik.github.io/php7-sapnwrfc
MIT License
90 stars 35 forks source link

Connect to a message server (Load Balancing) #159

Closed FlorinProfeanu closed 4 months ago

FlorinProfeanu commented 4 months ago

Hello,

Is it possible to connect to a message server (Load Balancing)?

Florin

gkralik commented 4 months ago

See Connecting to a SAP System, specifically the link to the sapnwrfc.ini parameters.

FlorinProfeanu commented 4 months ago

Hello,

I am trying to see if the setup pf ini file works also when using ashost. Then I will see how to manage balancing server.

This works: $config = [ 'ashost' => 'my_host', 'sysnr' => 'my_sysnr', 'client' => 'my_client', 'user' => 'my_user', 'passwd' => 'my_password', ]; $sapConnection = new SapConnection($config)

So I created a sapnwrfc.ini in the same folder with my PHP script: ASHOST=my_host SYSNR=my_sysnr CLIENT=my_client USER=my_user PASSWD=my_password

Then I do this: SAPNWRFC\Connection::setIniPath("sapnwrfc.ini");

The question is: how I write this when using ini file? $sapConnection = new SapConnection(????);

I want also to mention that the call to setIniPath does not fail, even if the file name mentioned as parameter does not exist.

Florin

gkralik commented 4 months ago
  1. SAPNWRFC\Connection::setIniPath() takes a path where the SDK searches for the INI file, not the path to the file itself. It will not error if the path or file does not exist, simply because the SDK itself does not seem to care.
  2. For connecting to a system entry defined in the INI file, just use the DEST parameter (see below):
DEST=test
ASHOST=<YOUR_HOST>
SYSNR=00
CLIENT=<YOUR_CLIENT<
USER=<USER>
PASSWD=<PWD>
TRACE=0
<?php

SAPNWRFC\Connection::setIniPath(__DIR__); // for an INI file in the same directory as the script
$connection = new SAPNWRFC\Connection([ 'DEST' => 'test']);

// Do stuff here...

I made a not to improve the documentation and provide an example.

FlorinProfeanu commented 4 months ago

The call SAPNWRFC\Connection::setIniPath(DIR) saved the day, thank you so much. Now is all good, including using MSHOST for balancing server. MSSERV was not needed in my case.