Coder Social home page Coder Social logo

Comments (15)

jayzalowitz avatar jayzalowitz commented on September 24, 2024

I am assuming https://github.com/elasticsearch/elasticsearch-php/blob/master/src/Elasticsearch/Client.php is the correct file, just want to be sure.

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

Hi there, sorry for the delay...I was on vacation without much email access.

The easiest solution is to run composer locally on your machine and upload the generated files to your server. Internally, composer is A) downloading all the dependencies and B) generating an "autoload.php" file which has code to include all the dependencies. Once everything is generated, the files and directory structure are static and can easily be moved around.

If you can't run composer at all, you will need to find a way to include all the relevant files (library + dependencies), not just the Client.php script. I can look into including a manual autoloader in the client itself so that composer isn't strictly required. It will still require you to download all the dependencies manually.

from elasticsearch-php.

jayzalowitz avatar jayzalowitz commented on September 24, 2024

Just a fyi, it seems as though you cannot load composer on micro ec2-instances on aws, so this is a really big issue for some people. looking into your fix.. Thanks.

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

Why does it not work on a micro instance? Memory constraints?

The general composer recommendation for small memory footprints is to enable swap, install to a local deployment and upload the composer.lock file to your micro instance.

Once the composer.lock is uploaded, you can do a composer install which should considerably less memory than a composer update.

from elasticsearch-php.

jayzalowitz avatar jayzalowitz commented on September 24, 2024

[ec2-user@ip-10-51-135-195 test]$ php composer.phar install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
[ec2-user@ip-10-51-135-195 test]$ php elasticdemo.php
PHP Fatal error: Class 'ElasticSearch\Client' not found in /var/www/html/elasticdemo.php on line 9

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

I'm sorry, I'm having a very hard time reproducing your problem. I just spun up a 64bit Amazon Linux on a micro instance. Everything worked as it should.

I updated packages, installed PHP, then installed tree:

[ec2-user@ip-10-141-184-210 ~]$ sudo yum update
[ec2-user@ip-10-141-184-210 ~]$ sudo yum install php
[ec2-user@ip-10-141-184-210 ~]$ sudo yum install tree

Then installed composer + the client:

[ec2-user@ip-10-141-184-210 ~]$ pwd
/home/ec2-user
[ec2-user@ip-10-141-184-210 ~]$ mkdir test
[ec2-user@ip-10-141-184-210 ~]$ cd test
[ec2-user@ip-10-141-184-210 test]$ nano composer.json

  GNU nano 2.0.9             File: composer.json                                

{
        "require": {
            "elasticsearch/elasticsearch": "~0.4"
        }
    }
                               [ Wrote 5 lines ]

[ec2-user@ip-10-141-184-210 test]$ curl -s http://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /home/ec2-user/test/composer.phar
Use it: php composer.phar
[ec2-user@ip-10-141-184-210 test]$ php composer.phar install --no-dev
Loading composer repositories with package information
Installing dependencies
  - Installing psr/log (1.0.0)
    Downloading: 100%         

  - Installing symfony/event-dispatcher (v2.4.1)
    Downloading: 100%         

  - Installing guzzle/guzzle (v3.8.0)
    Downloading: 100%         

  - Installing pimple/pimple (v1.1.0)
    Downloading: 100%         

  - Installing monolog/monolog (1.7.0)
    Downloading: 100%         

  - Installing elasticsearch/elasticsearch (v0.4.3)
    Downloading: 100%         

symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
Writing lock file
Generating autoload files
[ec2-user@ip-10-141-184-210 test]$ ls
composer.json  composer.lock  composer.phar  vendor
[ec2-user@ip-10-141-184-210 test]$ nano test.php

  GNU nano 2.0.9              File: test.php                                    

<?php
    require 'vendor/autoload.php';

    $client = new Elasticsearch\Client(); 

                               [ Wrote 4 lines ]
[ec2-user@ip-10-141-184-210 test]$ tree ../ -L 4
../
└── test
    ├── composer.json
    ├── composer.lock
    ├── composer.phar
    ├── test.php
    └── vendor
        ├── autoload.php
        ├── composer
        │   ├── autoload_classmap.php
        │   ├── autoload_namespaces.php
        │   ├── autoload_psr4.php
        │   ├── autoload_real.php
        │   ├── ClassLoader.php
        │   └── installed.json
        ├── elasticsearch
        │   └── elasticsearch
        ├── guzzle
        │   └── guzzle
        ├── monolog
        │   └── monolog
        ├── pimple
        │   └── pimple
        ├── psr
        │   └── log
        └── symfony
            └── event-dispatcher

15 directories, 11 files

[ec2-user@ip-10-141-184-210 test]$ php test.php
[ec2-user@ip-10-141-184-210 test]

I don't have elasticsearch running on the micro instance, so the client doesn't do anything. But it doesn't throw errors which means that the autoload has worked correctly, etc.

from elasticsearch-php.

jayzalowitz avatar jayzalowitz commented on September 24, 2024

Call $es = Client::connection(); and see if it still dosent fail (this is where it fails on my scripts)

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

There is no static method called "connection" in the client. In fact, there are no static methods in the entire library...

Can you gist up your complete code so I can see what you are attempting to do?

from elasticsearch-php.

jayzalowitz avatar jayzalowitz commented on September 24, 2024

Here is a Very limited version https://gist.github.com/jayzalowitz/7ab7b3b5e0233330ee65

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

It appears you are using the syntax for Nervetattoo/Elasticsearch, which is a different (unofficial) client library. Please consult the author of that library for syntax help.

Alternatively, if you want to use official Elasticsearch/Elasticsearch library...documentation is here: http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/index.html

The syntax is considerably different. Take some time to read the Quickstart and various examples in the readme. I'd be happy to help once you've converted the syntax over to this library. :)

from elasticsearch-php.

jayzalowitz avatar jayzalowitz commented on September 24, 2024

Nailed that issue, converted it over as far as I can understand and it still isn't functioning under localhost

neither
require 'vendor/autoload.php';

$esstartparams = array();
$esstartparams['hosts'] = array('http://localhost:9200');
$es = new Elasticsearch\Client($esstartparams);
nor
$es = new Elasticsearch\Client();
yeild anything other than a message similar to (With respect to the index data)
Notice: Undefined index: data in /var/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Namespaces/IndicesNamespace.php on line 307
when running any function, be it
$es->indices()->getMapping();
$es->search($searchParams);
$es->get($getParams);
any advice?

from elasticsearch-php.

jayzalowitz avatar jayzalowitz commented on September 24, 2024

Disregard this, this is what happens when your es is down ... different issue (micros+es just does not really stay alive on an active application)

from elasticsearch-php.

berendo avatar berendo commented on September 24, 2024

I'm not sure if this is the exact right context to ask this question, but could someone answer the quick question of what the specific dependency on the minimum PHP version of 5.3.9 (as opposed to 5.3.x) is? It was introduced here 182fcb8, but no specific reason was logged. Thanks much!

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

@jayzalowitz Ah, yeah, that particular bug was fixed in this commit (63cfea8). The client should throw an exception when ES is not available, but that bug was preventing it from happening. I'll be pushing a new tag soon and this bugfix will be available for regular installations.

@berendo In short, it's a bug in PHP versions under 5.3.9. I wrote a longer explanation here: #10 (comment) . I've had several people ask about the 5.3.9 dependency lately...I'll make a note and explanation about it in the readme so that it is easier to find.

(Also, sorry, I should have written a better commit message on that version change. Oops!)

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 24, 2024

@jayzalowitz I pushed the v0.4.4 tag this morning (https://github.com/elasticsearch/elasticsearch-php/tree/v0.4.4), which contains the fix for the no-host bug.

Closing this issue, let me know if you have any more problems!

from elasticsearch-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.