Download the PHP package hocvt/php-apache-tika without Composer
On this page you can find all versions of the php package hocvt/php-apache-tika. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-apache-tika
PHP Apache Tika
This tool provides Apache Tika bindings for PHP, allowing to extract text and metadata from documents, images and other formats.
The following modes are supported:
- App mode: run app JAR via command line interface
- Server mode: make HTTP requests to JSR 311 network server
Server mode is recommended because is 5 times faster, but some shared hosts don't allow run processes in background.
Although the library contains a list of supported versions, any version of Apache Tika should be compatible as long as backward compatibility is maintained by Tika team. Therefore, it is not necessary to wait for an update of the library to work with the new versions of the tool.
Features
- Simple class interface to Apache Tika features:
- Text and HTML extraction
- Metadata extraction
- OCR recognition
- Standarized metadata for documents
- Support for local and remote resources
- No heavyweight library dependencies
- Compatible with Apache Tika 1.7 or greater
- Tested up to 1.24
Requirements
- PHP 5.4 or greater
- Apache Tika 1.7 or greater
- Oracle Java or OpenJDK
- Java 6 for Tika up to 1.9
- Java 7 for Tika 1.10 or greater
- Tesseract (optional for OCR recognition)
Installation
Install using Composer:
If you want to use OCR you must install Tesseract:
- Fedora/CentOS:
sudo yum install tesseract
(use dnf instead of yum on Fedora 22 or greater) - Debian/Ubuntu:
sudo apt-get install tesseract-ocr
- Mac OS X:
brew install tesseract
(using Homebrew)
The library assumes tesseract
binary is in path, so you can compile it yourself or install using any other method.
Usage
Start Apache Tika server with caution:
If you are using JRE instead of JDK, you must run if you have Java 9 or greater:
Instantiate the class, checking if JAR exists or server is running:
If you want to use dependency injection, serialize the class or just delay the check:
You can use an URL too:
Use the class to extract text from documents:
Or use to extract text from images:
You can use an URL instead of a file path and the library will download the file and pass it to Apache Tika. There's
no need to add -enableUnsecureFeatures -enableFileUrl
to command line when starting the server, as described
here.
Methods
Here are the full list of available methods
Common
Tika file related methods:
Other Tika related methods:
Encoding methods:
Supported versions related methods:
Set/get a callback for sequential read of response:
Set/get the chunk size for secuential read:
Enable/disable the internal remote file downloader:
Command line client
Set/get JAR/Java paths (only CLI mode):
Web client
Set/get host properties
Set/get cURL client options
Set/get cURL client common options:
Troubleshooting
Empty responses or unexpected results
This library is only a proxy so if you get an empy responses or unexpected results the most common cause is Tika itself. A simple test is using the GUI to check the response:
- Run the Tika app without arguments:
java -jar tika-app-x.xx.jar
- Drop your file or select it using File -> Open
- Wait until the metadata appears
- Get the text or HTML using View menu
If the results are the same, you must take a look into Tika's Jira and open an issue if necessary.
Encoding
By default the returned text is encoded with UTF-8 but there are some issues with the encoding when using the app mode.
The Client::setEncoding()
method allows to set the expected encoding (this will be fixed in the upcoming 1.0 release).
Tests
Tests are designed to cover all features for all supported versions of Apache Tika in app mode and server mode. There are a few samples to test against:
- sample1: document metadata and text extraction
- sample2: image metadata
- sample3: text recognition
- sample4: unsupported media
- sample5: huge text for callbacks
- sample6: remote calls
- sample7: text encoding
Known issues
There are some issues found during tests, not related with this library:
- 1.9 version running Java 7 on server mode throws random error 500 (Unexpected RuntimeException)
- 1.14 version on server mode throws random errors (Expected ';', got ',') when parsing image metadata
- Tesseract slows down document parsing as described in TIKA-2359
Integrations
All versions of php-apache-tika with dependencies
ext-curl Version *