Announcement

#1 2017-01-16 17:17:01

CharlieM
Member
Gloucester, UK
2015-04-27
71

PiwigoPress

Hi

For a while now I've been trying to integrate PiwigoPress with a WordPress install. Finally I've discovered that it doesn't work because my host has loop back disabled. PiwigoPress is requesting the image data as a URL. EG:-

Code:

http://yarnwhispering.co.uk/pix/ws.php?method=pwg.images.getInfo&format=php&image_id=40

Although this works fine if you click on it in a browser loop back requests are blocked so when piwigpress.php makes the above request an error is returned:-

Code:

object(WP_Error)#3167 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(56) "cURL error 56: Failure when receiving data from the peer" } } ["error_data"]=> array(0) { } } array(6) { ["headers"]=> object(Requests_Utility_CaseInsensitiveDictionary)#3173 (1) { ["data":protected]=> array(4) { ["date"]=> string(29) "Mon, 09 Jan 2017 15:42:21 GMT" ["server"]=> string(20) "Apache/2.4.23 (Unix)" ["content-length"]=> string(3) "290" ["content-type"]=> string(29) "text/html; charset=iso-8859-1" } } ["body"]=> string(290) "

Line 119 tests for an error:-

Code:

if (!is_wp_error($response)) {

… and does nothing so no image.

Is there any way round this problem?

PP: 2.31
Piwigo: 2.74
PHP: 5.3.28
MySQL: 5.5.47
Piwigo Install: http://www.yarnwhispering.co.uk/pix/

Offline

 

#2 2017-01-16 19:06:23

eliz82
Member
Romania
2016-04-27
281

Re: PiwigoPress

CharlieM wrote:

it doesn't work because my host has loop back disabled.

not necessarily .
i encountered hosts that
1) block CURL with empty user agents or some specific user agents, that is why
[Github] piwigo2img file piwigo2img.php@L206
2) allow a single worker process for php fast-cgi (you need minimum 2 for making curl or fopen requests)
http://stackoverflow.com/questions/7230 … 62#7260962

Offline

 

#3 2017-01-16 21:35:54

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

Thanks for the speedy response @eliz82, please be patient with me as I'm less than proficient with this stuff by a long way; I'm not at all sure I understand your answer.

So firstly my host have confirmed that they block loop back. Secondly I tried to test it out with the following simple test:-

**link broken**

... and the host said yes that was what the error meant. Is there another possibility? Can I test it somehow

Offline

 

#4 2017-01-17 13:04:26

eliz82
Member
Romania
2016-04-27
281

Re: PiwigoPress

your code do not eliminate 1) and 2) from my response. even more you can also have FOPEN function disabled in php.ini

have you tried to make a "file_get_contents" to Piwigo api from another site to see if your FOPEN function is enabled in php.ini ?

try the piwigo demo site

Code:

$response = file_get_contents('http://piwigo.org/demo/ws.php?format=php&method=pwg.categories.getImages&recursive=true&per_page=2&order=date_available');

if is not possible then use curl instead fopen and like i said try to use a real browser user agent.

@edit: do you have a info.php page on your site?

Last edited by eliz82 (2017-01-17 13:08:19)

Offline

 

#5 2017-01-17 13:36:57

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

Thanks @eliz82

The demo code works fine and I've added phpinfo()

Offline

 

#6 2017-01-17 14:10:27

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

Classic (:

http://www.yarnwhispering.co.uk is down ATM. So http://www.yarnwhispering.co.uk/testloop.php isn't working at all!!!

Offline

 

#7 2017-01-17 21:25:37

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

Offline

 

#8 2017-01-18 07:29:49

eliz82
Member
Romania
2016-04-27
281

Re: PiwigoPress

you could try plg function for opening the url
http://piwigo.org/forum/viewtopic.php?p … 34#p158834

or my function
[Github] piwigo2img file piwigo2img.php@L203-L224

they try to use multiple methods.

example:

Code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$base_url = 'http://yarnwhispering.co.uk/pix/ws.php?format=php&method=';
$url = $base_url.'pwg.images.getInfo&format=php&image_id=40';
fetchRemote($url, $result);
$result = unserialize($result);

echo '<pre>';
print_r($result); //DEBUG - show the array values
echo '</pre>';

/**
 * Retrieve data from external URL
 *
 * @param string $src: URL
 * @param global $dest: can be a file ressource or string
 * @return bool
 */
function fetchRemote($src, &$dest, $user_agent='Mozilla/5.0 (Windows NT 5.1; rv:25.0) Gecko/20100101 Firefox/25.0', $step=0)
{
  // After 3 redirections, return false
  if ($step > 3) return false;

  // Initialize $dest
  is_resource($dest) or $dest = '';

  // Try curl to read remote file
  if (function_exists('curl_init'))
  {
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_URL, $src);
    @curl_setopt($ch, CURLOPT_HEADER, 1);
    @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $content = @curl_exec($ch);
    $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    @curl_close($ch);
    if ($content !== false and $status >= 200 and $status < 400)
    {
      if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
      {
        return fetchRemote($m[1], $dest, $user_agent, $step+1);
      }
      $content = substr($content, $header_length);
      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
      return true;
    }
  }

  // Try file_get_contents to read remote file
  if (ini_get('allow_url_fopen'))
  {
    $content = @file_get_contents($src);
    if ($content !== false)
    {
      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
      return true;
    }
  }

  // Try fsockopen to read remote file
  $src = parse_url($src);
  $host = $src['host'];
  $path = isset($src['path']) ? $src['path'] : '/';
  $path .= isset($src['query']) ? '?'.$src['query'] : '';

  if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false)
  {
    return false;
  }

  fwrite($s,
    "GET ".$path." HTTP/1.0\r\n"
    ."Host: ".$host."\r\n"
    ."User-Agent: ".$user_agent."\r\n"
    ."Accept: */*\r\n"
    ."\r\n"
  );

  $i = 0;
  $in_content = false;
  while (!feof($s))
  {
    $line = fgets($s);

    if (rtrim($line,"\r\n") == '' && !$in_content)
    {
      $in_content = true;
      $i++;
      continue;
    }
    if ($i == 0)
    {
      if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m))
      {
        fclose($s);
        return false;
      }
      $status = (integer) $m[2];
      if ($status < 200 || $status >= 400)
      {
        fclose($s);
        return false;
      }
    }
    if (!$in_content)
    {
      if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m))
      {
        fclose($s);
        return fetchRemote(trim($m[1]),$dest,$user_agent,$step+1);
      }
      $i++;
      continue;
    }
    is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line;
    $i++;
  }
  fclose($s);
  return true;
}
?>

if this also do not work then maybe host blocked some loopback in their firewall (you cannot block all loopback because webserver also make loopback to php-fcgi), or they allow a single worker proccess  for php-fcgi.
if you have access to ssh you could try "iptables --list" to list the rules. or some host allow you to make a php-cgi in the root of your site and put a "php.ini" file and a "php5.fcgi" file. in that files you can specify more worker process for fast cgi.

if this is not posible then you can try the json output of the Piwigo Api with javascript. I think javascript is totally executed on the client side, so is the client who make the connection to the piwigo api ws.php file. so it may work.

example: http://piwigo.org/forum/viewtopic.php?p … 78#p165578

Last edited by eliz82 (2017-01-18 07:31:57)

Offline

 

#9 2017-01-18 07:52:39

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

@eliz82

Just a blank screen I'm afraid:-

http://www.yarnwhispering.co.uk/testloop2.php

Offline

 

#10 2017-01-18 07:54:59

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

It is possible to add a php.ini to the root. Not sure about php5.fcgi. What would I put in them?

Offline

 

#11 2017-01-18 09:16:31

eliz82
Member
Romania
2016-04-27
281

Re: PiwigoPress

my "cgi-bin" folder with "php5.fcgi" looks like this

Code:

#!/bin/sh
export PHP_FCGI_CHILDREN=2
export PHP_FCGI_MAX_REQUESTS=1000
exec /usr/local/cpanel/cgi-sys/php5

is the PHP_FCGI_CHILDREN=2 who let you run two php-cgi workers. i already posted this link
http://stackoverflow.com/questions/7230 … 62#7260962

and you must give execution rights to both php.ini and php5.fcgi , chmod 755
but what i dint remember well is if the webserver need to be restarted to execute the files.

Offline

 

#12 2017-01-19 16:16:16

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

This doesn't seem to have made any difference.

Offline

 

#13 2017-01-19 17:39:59

eliz82
Member
Romania
2016-04-27
281

Re: PiwigoPress

CharlieM wrote:

This doesn't seem to have made any difference.

not many hosts allow this kind of fcgi configuration for their clients.

Offline

 

#14 2017-01-20 11:10:54

CharlieM
Member
Gloucester, UK
2015-04-27
71

Re: PiwigoPress

I guess this can't be resolved then?

Offline

 

#15 2017-01-20 11:54:20

eliz82
Member
Romania
2016-04-27
281

Re: PiwigoPress

CharlieM wrote:

I guess this can't be resolved then?

with php and without support from your host i think not.

have you tried to do the same thing in javascript and using Piwigo api json output like I suggested ?

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact