Actor

apify/example-php

  • Builds
  • latest 0.0.3 / 2018-02-05
  • Created 2017-10-25
  • Last modified 2018-09-12
  • grade 8

Description

Example act using PHP as the main language.


API

To run the actor, send a HTTP POST request to:

https://api.apify.com/v2/acts/apify~example-php/runs?token=<YOUR_API_TOKEN>

The POST payload will be passed as input for the actor. For more information, read the docs.


Example input

Content type: application/json; charset=utf-8

{ "hello": 123 }

Readme

This is simple example how to use PHP in Apify. It uses custom Dockerfile based on php:7.0-cli image.

Dockerfile

FROM php:7.0-cli

COPY ./* ./

CMD [ "php", "./main.php" ]

main.php

<?php
print "Starting ...\n";
print "ENV vars:\n";
print_r($_ENV);
print "Fetching http://example.com ...\n";
$exampleComHtml = file_get_contents('http://example.com');
print "Searching for <h1> tag contents ...\n";
preg_match_all('/<h1>(.*?)<\/h1>/', $exampleComHtml, $matches);
print "Found: " . $matches[1][0] . "\n";
print "I am done!\n";