PHP API client FAQ
On this page
- 1. Why am I getting “Impossible to connect”, “Unable to connect”, or “Unreachable hosts” errors?
- 2. How can I stay up-to-date with new major versions of the API clients?
- 3. Why am I getting the “Record at the position XX objectID=XX is too big” error?
- 4. Why can’t I find the object with the findObject method?
- 5. Why can’t I use the generateSecuredApiKey method without restrictions?
- 6. Why does the replaceAllObjects method hang forever?
- 7. Why doesn’t replaceAllObjects replace all the objects and leave a temporary index?
- 8. When using replaceAllObjects, why does the destination index contains fewer records than expected?
- 9. How to delete objects without their objectIDs?
- 10. Why is there a Cross-Origin Resource Sharing (CORS) error?
- 11. How can I fix the curl error 28: Resolving timed out error?
- 12. How can I log Algolia’s requests and responses?
- 13. Why is searchDisjunctiveFaceting no longer available in v2?
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting “Impossible to connect”, “Unable to connect”, or “Unreachable hosts” errors?
If you’re facing connectivity issues, here are some checks you should perform on your side before contacting our support team:
- Are you using the correct application ID and API key? You can find these credentials on your Algolia dashboard.
- Did anything recently change in your code or on your data center provider’s side? Make sure to check their status too.
- Using Firebase? The Firebase free plan only allows requests to other Google APIs. Because of this limitation, you can only use Algolia with Firebase if you’re on a paid Firebase tier.
If you’re unable to debug the problem yourself, contact the Algolia support team with the following information:
- API client and version (e.g., JavaScript API client 4.3.0)
- Language and version (e.g., PHP 7.1)
- Code snippet to reproduce the issue
- Error message or stack trace (if applicable)
- The Algolia index name with which you’re experiencing issues
- The precise timeline (in the UTC time zone of the event)
- Having trouble connecting to the Algolia API from your servers? Send us the link generated by the diagnostic script command on your impacted servers:
Copy
1
curl -sL https://algolia.com/downloads/diag.sh > ./diag.sh && sudo ./diag.sh ApplicationID
Ensure that you replace “ApplicationID” with your actual Algolia Application ID.
- Having trouble connecting to the Algolia API from your browser? Head over to community.algolia.com/diag/ and send us this output instead.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
How can I stay up-to-date with new major versions of the API clients?
You can check out our changelog page.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why am I getting the “Record at the position XX objectID=XX is too big” error?
You’re getting this error because there’s a size limit for records. Make sure you reduce your records and try again.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why can’t I find the object with the findObject
method?
If you need to get an object from your index, you should use the getObjects
method.
You should only use findObject
to debug the relevance of a specific object, and in development mode. This method accepts a condition and returns the first matching object along with its position information in the result set. Note that the result set is limited to a certain amount of records, not the entire index.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why can’t I use the generateSecuredApiKey
method without restrictions?
You must add at least one restriction to generate a valid secured API key. If there are no restrictions, there’s no point in hiding the original API key since the generated secured API key has the same permissions and constraints.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why does the replaceAllObjects
method hang forever?
When an index doesn’t exist, and you’re using the replaceAllObjects
with the safe
parameter, the method can get stuck and hang forever. This happens because the method expects the index to exist.
To fix this issue, you can either create the index using the Algolia dashboard, or with the API using an empty setSettings
.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why doesn’t replaceAllObjects
replace all the objects and leave a temporary index?
If you’ve performed replaceAllObjects
, it may still be in progress. If you suspect that the operation didn’t complete successfully and left a temporary index, make sure to double-check the number of records of the temporary index.
If the number of records of the temporary index doesn’t change for 10 minutes, there’s a chance the operation didn’t finish because of an error while indexing records in the temporary index. To debug this, we recommend you check the logs in your Algolia dashboard for the temporary index and see if you find any errors.
Besides, you may also be able to debug the issue in your development console or logging platform.
If you’re unable to debug the problem yourself, contact the Algolia support team with the following information:
- API client and version (e.g., Go client 3.4.0)
- Language and version (e.g., Java 1.8)
- Code snippet to reproduce the issue
- Error message or stack trace (if applicable)
- The Algolia index name with which you’re experiencing issues
- The precise timeline (in the UTC time zone of the event)
It’s recommended to use the Kotlin API client, which is better suited for Android development.
When using replaceAllObjects
, why does the destination index contains fewer records than expected?
This issue may happen when indexing a large number of records, and because of the asynchronous nature of Algolia. You can fix this issue with the safe
parameter.
If you need to index many records, you may want to process replaceAllObjects
in the background, as the safe
parameter may cause the operation to take longer than expected.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
How to delete objects without their objectID
s?
The most convenient way is to use the deleteBy
method, as it enables you to delete one or more objects based on filters (numeric, facet, tag or geo queries).
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why is there a Cross-Origin Resource Sharing (CORS) error?
The Algolia APIs support cross-origin requests. If you’re getting such an error when indexing or searching, first make sure that your application ID is correct. An incorrect application ID results in querying an endpoint that doesn’t exist, thus resulting in the error.
If the issue persists despite correct credentials, contact the Algolia support team.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
How can I fix the curl error 28: Resolving timed out
error?
You can encounter the error curl error 28: Resolving timed out after 2000 milliseconds
when curl isn’t able to connect to Algolia within 2000 milliseconds.
This could be because of a potential outage, but more often it’s because of the physical distance between Algolia’s servers and your server.
Make sure your server is located as close as possible to the Algolia data center you selected when creating your app.
If the error still occurs, and you’re certain your server can connect to other online services, you can try to change the default timeouts of the API client.
You can do this by using the setConnectTimeout
, setReadTimeout
, and setWriteTimeout
methods on the configuration object.
1
2
3
4
5
6
$config = SearchConfig::create('YourAppID', 'YourAPIKey');
$config->setConnectTimeout(5); // In seconds. You can set these values higher if needed.
$config->setReadTimeout(5); // In seconds. You can set these values higher if needed.
$config->setWriteTimeout(5); // In seconds. You can set these values higher if needed.
$client = SearchClient::createWithConfig($config);
If the issue persists, contact the Algolia support team.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
How can I log Algolia’s requests and responses?
For debugging purposes, you may need to log Algolia requests and responses. To do so, you can activate the debug logger like so:
1
\Algolia\AlgoliaSearch\Log\DebugLogger::enable();
Keep in mind that enabling the DebugLogger
outputs the raw content of every request and response to the console. Make sure to never enable the DebugLogger
in production.
It’s recommended to use the Kotlin API client, which is better suited for Android development.
Why is searchDisjunctiveFaceting
no longer available in v2?
The searchDisjunctiveFaceting
method is deprecated and no longer exists in the v2 of the PHP API client.
For now, we don’t plan on bringing this method back to the PHP client. Meanwhile, you can use this code snippet as a replacement.