Code Monkey home page Code Monkey logo

Comments (11)

jcupitt avatar jcupitt commented on June 15, 2024

Hello, that's an interesting idea. It's certainly threaded, so it should work. The node.js libvips binding is async.

You'd need to write a little wrapper to do async dispatch I suppose, but I've never looked into it. You'd need to ask a PHP expert.

from php-vips-ext.

uasan avatar uasan commented on June 15, 2024

Working example using thread pool from libuv.

Required: PHP 7 ZTS, and php-uv module.
pecl install uv
http://pecl.php.net/package/uv

<?php

$loop  = uv_default_loop();

$thread = function()
{
	echo "THREAD-CALL\n";

	$opt =
	[
		'height'      => 1920,
		'size'        => 2,
		'auto_rotate' => 1,
		'crop'        => 0,
		'linear'      => 0
	];

	$img = vips_call('thumbnail', null, '/opt/exif.jpg', 1920, $opt)['out']?? null;

	if($img === null)
	{
		echo vips_error_buffer()."\n";
	}
	else
	{
		vips_image_write_to_file($img, '/var/www/thumbnail.jpg');
	}
};

$after = function()
{
	echo "THREAD-CALL-AFTER\n";
};

for($i = 0; $i < 4; $i++)
{
	uv_queue_work($loop, $thread, $after);
}

uv_run($loop);

vips_call() - Running in a separate thread, is overheads, async callback be rationally.

from php-vips-ext.

jcupitt avatar jcupitt commented on June 15, 2024

Woah, nice job!

from php-vips-ext.

uasan avatar uasan commented on June 15, 2024

PHP ZTS thread pool from libuv, often segmentation crash :(

We used GraphicsMagick, as worker, send to STDIN
http://www.graphicsmagick.org/batch.html

Run (spawn child process)
gm batch -

Write to STDIN
convert big.jpg -format "%w %h %[exif:DateTime]" -write info:- -strip -resize "250x250>" small.jpg\n

Read from STDOUT
800 600 2015-06-12\n

It is safely and works quickly, one worker process gm, executing requests the pipeline mode from STDIN, in vips_tools such prog there is? :)

Thank.

from php-vips-ext.

jcupitt avatar jcupitt commented on June 15, 2024

Yes, vips has vipsthumbnail, a command-line resizer. It's file operations only though, so you'd need to go via the filesystem.

We should be able to get the libuv one working though, I wonder what the issue is. I'll see if I can reproduce it here.

from php-vips-ext.

uasan avatar uasan commented on June 15, 2024

I looked at vips lua, I can write lua script, use as child PHP process

$work = Worker::spawn('luajit my_script.lua');
$work->write('...'); // write to STDIN script.lua

from php-vips-ext.

jcupitt avatar jcupitt commented on June 15, 2024

I'm working on vips-lua at the moment, it's not finished yet. Another week or two.

You could write a php script and call that as a child process, that would be a simple solution.

libvips is used with libuv in node.js with very large deployments (tumblr, etc.) and it works fine, so I think the crashes you are seeing must just be problems with php-vips-ext. I suppose we must add some locks to this file:

https://github.com/jcupitt/php-vips-ext/blob/master/vips.c

Do you know what the rules are for what calls need locks? Is there a document I can read?

from php-vips-ext.

jcupitt avatar jcupitt commented on June 15, 2024

Do you know lua well? If you do, some help on lua-vips would be very welcome. I'm not a lua expert at all, and it would be wonderful if someone who knew what they were doing could check it for dumbness.

from php-vips-ext.

uasan avatar uasan commented on June 15, 2024

Do you know what the rules are for what calls need locks? Is there a document I can read?

I'm not an expert in multithreading, my experiments showed that PHP ZTS and libuv without Vips, segmentation errors, so I abandoned this idea.

Crashing main PHP process is not allowed, our main PHP process is engaged in important business logic.

Do you know lua well? If you do, some help on lua-vips would be very welcome. I'm not a lua expert at all, and it would be wonderful if someone who knew what they were doing could check it for dumbness.

I wrote my first script on lua yesterday, i learning :)

from php-vips-ext.

uasan avatar uasan commented on June 15, 2024

I resolve the cause, this problem in php-ext-raphf is thread not safe, without it everything works well.

from php-vips-ext.

jcupitt avatar jcupitt commented on June 15, 2024

Good news! I'll close.

from php-vips-ext.

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.