oci-php-sdk provides an SDK for PHP that you can use to manage your Oracle Cloud Infrastructure resources.
The project is open source and maintained by Oracle Corp. The home page for the project is here.
/path/to/artifacts
oci-php-sdk-0.0.1-2021-11-02T13-44-29.zip
, in that directory.
oracle/oci-php-sdk
version 0.0.1
to your composer.json
fileartifact
to your composer.json
file, where url
is set to the directory with the zip file, e.g. /path/to/artifacts
Here is a complete example of such a composer.json
file:
{
"name": "oracle/oci-php-sdk-consumer",
"type": "project",
"require": {
"oracle/oci-php-sdk": "0.0.1"
},
"repositories": [
{
"type": "artifact",
"url": "/path/to/artifacts"
}
]
}
vendor
directory, and composer.lock
file:
composer clear-cache && rm -rf vendor; rm composer.lock
vendor
contains the latest contents from the zip file.composer install
src/test.php
, require the vendor/autoload.php
file, and then use the OCI PHP SDK classes you need. For example:<?php
require 'vendor/autoload.php';
use Oracle\Oci\Common\UserAgent;
echo "UserAgent: " . UserAgent::getUserAgent() . PHP_EOL;
?>
php src/test.php
oracle/oci-php-sdk
version dev-master
to your composer.json
filegit
to your composer.json
file, where url
is set to the same URL you use to git clone
, e.g. https://github.com/organization/my-repo.git
https://github.com/organization/my-repo.git
is not an actual Git repository with the OCI PHP SDK.Here is a complete example of such a composer.json
file:
{
"name": "oracle/oci-php-sdk-consumer",
"type": "project",
"require": {
"oracle/oci-php-sdk": "dev-master"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/organization/my-repo.git"
}
]
}
vendor
directory, and composer.lock
file:
composer clear-cache && rm -rf vendor; rm composer.lock
vendor
contains the latest contents from the Git master
branchcomposer install
src/test.php
, require the vendor/autoload.php
file, and then use the OCI PHP SDK classes you need. For example:<?php
require 'vendor/autoload.php';
use Oracle\Oci\Common\UserAgent;
echo "UserAgent: " . UserAgent::getUserAgent() . PHP_EOL;
?>
php src/test.php
Examples can be found here.
You may run any example by invoking the php
command with the example you want to run,
for example: php tests/Oracle/Oci/Examples/ObjectStorageExample.php
The following has worked for installing PHP 8.0 on Oracle Linux 8:
sudo dnf module list php
sudo dnf install @php:8.0 -y
Install Composer as package manager for PHP:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
The tests/Oracle/Oci/Examples/InstancePrincipalsExample.php
and tests/Oracle/Oci/Examples/CachingInstancePrincipalsExample.php
examples must be run on an OCI instance. To set it up, you can follow these steps:
Create a dynamic group. You can use a matching rule like this to get all instances in a certain compartment:
Any {instance.compartment.id = '<ocid-of-compartment>'}
Start an OCI instance. Make sure that it is matched by the dynamic group, e.g. by creating it in the correct compartment.
Create a policy for the dynamic group that grants the desired permissions. For example:
Allow dynamic-group <name-of-dynamic-group> to manage buckets in compartment <name-of-compartment>
Allow dynamic-group <name-of-dynamic-group> to manage objects in compartment <name-of-compartment>
Allow dynamic-group <name-of-dynamic-group> to manage objectstorage-namespaces in compartment <name-of-compartment>
Install PHP 8.0 on Oracle Linux. See above.
Copy the OCI PHP SDK and this example to the OCI instance (using scp
or rsync
).
Run Composer to download the required packages:
composer update
composer install
SSH into the OCI instance.
Run the example:
php tests/Oracle/Oci/Examples/InstancePrincipalsExample.php
Run the Instance Principal-specific unit tests:
php vendor/bin/phpunit --group InstancePrincipalsRequired
See CHANGELOG.
This project welcomes contributions from the community. Before submitting a pull request, please review our contribution guide
Please consult the security guide for our responsible security vulnerability disclosure process
You can find information on any known issues with the SDK here.
The OCI PHP SDK is based on the GuzzleHttp\Client
; therefore, it has the same threading behavior as GuzzleHttp\Client
.
There does not appear to be good documentation on the thread safety of GuzzleHttp\Client
, but there are hints that it is NOT thread-safe:
These issues are not unique to the OCI PHP SDK, and the solution seems to simply be to create a separate client per thread.
Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
See LICENSE for more details.