John Davidson

xampp - Windows 11 + PHP + Imagick issue with second browser window and timeout

0 comments
Message:


I have a PHP script that modify images using ImageMagick and the script runs for a very long time. Now I want to start a second PHP script while the first script is running, which also processes images, but this script loads dead and breaks after 30s and do nothing. ImageMagick is responsible for this. As soon as I call $image = new Imagick; in second PHP script this script is on hold and waits until script 1 is finished. Can anyone tell me why this is happening and how to solve it for Windows? I use here Xampp with PHP 8.1 on Windows 11. Maybe a stupid question, but I have not found anything on this.


script 1
<?php $image = new Imagick; sleep(10); ?>


script 2
<?php $image = new Imagick; ?>


Start both scripts and script 1 block imagick for 10s, so script 2 is waiting 10s to finish.



My Answer:
It sounds like the issue you are experiencing is related to how ImageMagick handles multiple processes on Windows. ImageMagick may be locking resources or causing conflicts when multiple instances are trying to access it simultaneously.

One possible solution is to try using separate instances of ImageMagick for each PHP script. You can do this by setting the environment variable MAGICK_THREAD_LIMIT to 1 before calling the Imagick constructor in your second PHP script. This will limit ImageMagick to only using one thread, potentially allowing both scripts to run concurrently.

You can set the environment variable in your PHP script like this:

php
putenv('MAGICK_THREAD_LIMIT=1');


Then, in your second PHP script, try creating the Imagick object:

php
putenv('MAGICK_THREAD_LIMIT=1');
$image = new Imagick;


This should help prevent conflicts between the two scripts when using ImageMagick. Give it a try and see if it resolves your issue.

Rate this post

5 of 5 based on 3783 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us