Skip to content
Closed

Pr/7975 #7986

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/connections/sources/catalog/libraries/server/php/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ support_type: maintenance
---
Segment's PHP library lets you record analytics data from your PHP code. The requests hit Segment servers, and then Segment routes your data to any analytics service you enable on your destinations page.

This library is open-source, so you can [check it out on GitHub](https://github.com/segmentio/analytics-php).
This library is open-source, so you can [check it out on GitHub](https://github.com/segmentio/analytics-php){:target="_blank”}.

PHP is a little different than Segment's other server-side libraries because it is a single-threaded language. Segment worked to make the PHP library as performant as possible, while still leaving you room to tune the settings for your application. If you want to learn more about tuning your settings for high performance, be sure to read through the section on [configuration](#configuration) at the end of this guide.

Want to stay updated on releases? Subscribe to the [release feed](https://github.com/segmentio/analytics-php/releases.atom).
Want to stay updated on releases? Subscribe to the [release feed](https://github.com/segmentio/analytics-php/releases.atom){:target="_blank”}.

## Getting Started
## Getting started

Clone the repository from GitHub into your desired application directory.

Expand Down Expand Up @@ -103,7 +103,7 @@ Find details on the **identify method payload** in the [Segment Spec](/docs/conn

Track lets you record the actions your users perform.Every action triggers what Segment calls an "event", which can also have associated properties.

You'll want to track events that are indicators of success for your site, like **Signed Up**, **Item Purchased** or **Article Bookmarked**.
You'll want to track events that are indicators of success for your site, like **Signed Up**, **Item Purchased**, or **Article Bookmarked**.

To get started, Segment recommends tracking just a few important events. You can always add more later.

Expand Down Expand Up @@ -318,7 +318,7 @@ Segment::track(array(

For more details about Alias including the **Alias call payload**, check out the [Segment Spec](/docs/connections/spec/alias/).

## Historical Import
## Historical import

You can import historical data by adding the `timestamp` argument to any of your method calls. This can be helpful if you've just switched to Segment.

Expand Down Expand Up @@ -402,7 +402,7 @@ Segment::init("YOUR_WRITE_KEY", array(
</tr>
</table>

### Lib-Curl Consumer
### Lib-Curl consumer

The [lib-curl consumer](https://github.com/segmentio/analytics-php/blob/master/lib/Segment/Consumer/LibCurl.php) is a reliable option for low-volume sources or if you want fast response times under light loads. The library runs synchronously, queuing calls and sending them in batches to Segment's servers. By default, this happens every 100 calls, or at the end of serving the page. By default, Segment ignores http responses to optimize the library's speed, but you can choose to wait for these responses by enabling debug mode.

Expand All @@ -425,7 +425,7 @@ Segment::init("YOUR_WRITE_KEY", array(
```


### Fork-Curl Consumer
### Fork-Curl consumer

The [fork-curl consumer](https://github.com/segmentio/analytics-php/blob/master/lib/Segment/Consumer/ForkCurl.php) should work best for cases where you can't use persistent sockets, or want to ensure quick response times under light load. It works by creating an in-memory queue which buffers track and identify calls. The queue is flushed by forking an async `curl` process that sends a batch request. By default, this happens every `100` calls, or at the end of serving the page. This consumer will spawn a separate process for each request which tracks events. If your servers are handling more than 20 requests per second, you may want to look at the [file consumer](#file-consumer).

Expand All @@ -452,7 +452,7 @@ Segment::init("YOUR_WRITE_KEY", array(
</table>


### Socket Consumer
### Socket consumer

If you can't spawn other processes from your PHP scripts, you can use the [socket consumer](https://github.com/segmentio/analytics-php/blob/master/lib/Segment/Consumer/Socket.php), which will allow you to make requests to Segment. Each time a track or identify call is made, it will initiate a socket request to Segment's servers. The socket request is about as async as you can get with PHP, where the request will write the event data and close the connection before waiting for a response. However, if your servers are dealing with more than 100s of requests per second or cannot use a persistent connection, you may want to use one of the other consumers instead.

Expand Down Expand Up @@ -483,7 +483,7 @@ Segment::init("YOUR_WRITE_KEY", array(
</table>


### File Consumer
### File consumer

The [file consumer](https://github.com/segmentio/analytics-php/blob/master/lib/Segment/Consumer/File.php) is a more performant method for making requests to Segment. Each time a track or identify call is made, it will record that call to a log file. The log file is then uploaded "out of band" by running the `file.php` file found in [the analytics-php repository](https://github.com/segmentio/analytics-php/blob/master/lib/Segment/Consumer/File.php).

Expand Down Expand Up @@ -526,8 +526,6 @@ $ sudo service cron reload # reload the cron daemon
{% include content/server-side-troubleshooting.md %}


## 3rd-Party Libraries
## 3rd party libraries

If you only need support for PHP5, the team at Underground Elephant has released a [3rd-party library](https://github.com/uecode/segment-io-php) based on Guzzle.

Alt Three Segment is a Segment bridge for Laravel. The GitHub repo can be found here: [AltThree/Segment](https://github.com/AltThree/Segment){:target="_blank”}.
Laravel Segment is a Segment SDK for Laravel. View the [slashEquip/laravel-segment](https://github.com/slashequip/laravel-segment){:target="_blank”} GitHub repo to learn more.