Installing pThreads in Windows - php

Can anyone guide me in installing pThreads in Windows .
Actually i want to enable Threads in PHP .
require_once( 'Thread.php' );
// test to see if threading is available
if( ! Thread::available() ) {
die( 'Threads not supported' );
}
// function to be ran on separate threads
function paralel( $_limit, $_name ) {
for ( $index = 0; $index < $_limit; $index++ ) {
echo 'Now running thread ' . $_name . PHP_EOL;
sleep( 1 );
}
}
// create 2 thread objects
$t1 = new Thread( 'paralel' );
$t2 = new Thread( 'paralel' );
// start them
$t1->start( 10, 't1' );
$t2->start( 10, 't2' );
// keep the program running until the threads finish
while( $t1->isAlive() && $t2->isAlive() ) {
}
Error displaying is "Threads not supported."
My PHP version 5.3.4 .

Install ZTS (thread safe) PHP (obligation)
http://windows.php.net/downloads/releases/php-5.5.6-Win32-VC11-x86.zip
Download Pthread and install
http://windows.php.net/downloads/pecl/releases/pthreads/
Move php_pthreads.dll to the php\ext\ directory.
Move pthreadVC2.dll to the php\ directory.
enter extension=php_pthreads.dll to php.ini
try examples
https://github.com/krakjoe/pthreads/tree/master/examples

The code you have posted is not compatible with pthreads.
Windows binaries for pthreads are available http://windows.php.net/downloads/pecl/releases/pthreads/
Simply download the release, unpack the extension dll (php_pthreads.dll) to your extension directory and the runtime dll (pthreadVC2.dll) to your php directory (same dir as php.exe) and add extension=php_pthreads.dll to your configuration
Example pthreads code can be found on github http://github.com/krakjoe/pthreads

Related

phpmyadmin error when installing in arch linux

i have tried installing phpmyadmin on arch linux but every time i open localhost/phpmyadmin,i get this text.
PHP 7.2.5+ is required.
Currently installed version is: ' . PHP_VERSION . '
'); } // phpcs:disable PSR1.Files.SideEffects define('PHPMYADMIN', true); // phpcs:enable require_once ROOT_PATH . 'libraries/constants.php'; /** * Activate autoloader */ if (! #is_readable(AUTOLOAD_FILE)) { die( '
File ' . AUTOLOAD_FILE . ' missing or not readable.
' . '
Most likely you did not run Composer to ' . '' . 'install library files.
' ); } require AUTOLOAD_FILE; global $route, $containerBuilder, $request; Common::run(); $dispatcher = Routing::getDispatcher(); Routing::callControllerForRoute($request, $route, $dispatcher, $containerBuilder);
i have installed php and this its version
PHP 8.1.8 (cli) (built: Jul 9 2022 06:10:37) (NTS)
i have also tried following all the steps in arch documentation (https://wiki.archlinux.org/title/phpMyAdmin)
but when i try to open the url(localhost/phpmyadmin),it outputs a blank page with no
body so i had to reset all the configs to default.help me out.thanks alot
to solve this issue,i reinstalled everything again,followed the steps in (https://wiki.archlinux.org/title/phpMyAdmin) and in /etc/php/php.ini,uncommented the extension 'bz2 and mysqli'

EasyPHP Devserver and PHPMyAdmin 5.1.1 - Composer dependencies issue: openssl

Getting the following message when attempting to run PhpMyAdmin 5.1.1 within EasyPHP Devserver 17. This is with MySQL 8.0 and PHP 7.4:
Composer detected issues in your platform: Your Composer dependencies require the following PHP extensions to be installed: openssl
I have checked the php.ini and it contains extension=openssl without comment.
Full results from php -i cmd on my Windows 10 machine.
UPDATE
The above error is produced when attempting to open PhpMyAdmin 5.1.1 from EasyPHP Devserver dashboard.
Also, php -i cmd shows:
Configuration File (php.ini) Path =>
Loaded Configuration File => E:\Projects\PHP Migration\EasyPHP-Devserver-17\eds-binaries\php\php7427vc15x86x220629181102\php.ini
...
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.1.1l 24 Aug 2021
OpenSSL Header Version => OpenSSL 1.1.1l 24 Aug 2021
Openssl default config => C:\Program Files (x86)\Common Files\SSL/openssl.cnf
Directive => Local Value => Master Value
openssl.cafile => no value => no value
openssl.capath => no value => no value
C:\Program Files (x86)\Common Files\SSL/openssl.cnf does not exist. I guess that might be a problem?
The same error occurs with this PHP script:
if (!(PHP_VERSION_ID >= 70103)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.1.3". You are running ' . PHP_VERSION . '.';
}
$missingExtensions = array();
extension_loaded('hash') || $missingExtensions[] = 'hash';
extension_loaded('iconv') || $missingExtensions[] = 'iconv';
extension_loaded('json') || $missingExtensions[] = 'json';
extension_loaded('mysqli') || $missingExtensions[] = 'mysqli';
extension_loaded('openssl') || $missingExtensions[] = 'openssl';
extension_loaded('pcre') || $missingExtensions[] = 'pcre';
extension_loaded('xml') || $missingExtensions[] = 'xml';
if ($missingExtensions) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
}
if ($issues) {
echo 'Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues);
exit(104);
}
Any ideas how to fix this?

Detect a WordPress Installation

How to detect if a folder is having a WordPress installation or not ?
WP-CLI does that and gives the error This does not seem to be a WP installation, and detects correctly if the directory has a WP install even if it is in any of the subfolders (wp-includes/images or wp-includes/js ) .
I went through the code and it searches for index.php and compares content with the original index.php . One more thing it does is to check for the presence of wp-includes/version.php . Got the idea but how it works on subfolders like those mentioned above is still not clear . Do anybody have any idea on how to do this ? Thanks in advance .
Look for the wp-config.php file. If you find it, require it, then try to use its constants DB_HOST, DB_USER, DB_PASSWORD and DB_NAME to connect to the WordPress database associated with the WordPress instance. If that works, you very likely have a working WordPress instance.
If your current working directory doesn't have wp-config.php look at parent directories recursively until you (a) find it or (b) come to the top level directory.
wp-cli does more elaborate things. But this should work for you.
So i have scribbled a script that detects a WP install . It works as expected inside a wp install folder , but if it is not inside a WordPress install it executes an infinite loop . Can somebody guide on how to stop at top level directory as mentioned by #O.Jones ? Here is my code .
<?php
function get_wp_index($dir=null) {
if(is_null($dir)){
$dir = getcwd();
}
echo "Currently Looking \n";
echo $dir;
$name = $dir.DIRECTORY_SEPARATOR."index.php";
if ( file_exists( $name ) ) {
$index_code = (file_get_contents($name));
if ( preg_match( '|^\s*require\s*\(?\s*(.+?)/wp-blog-header\.php([\'"])|m', $index_code, $matches ) ) {
echo "Is a WP Install";
return;
} else {
echo "Has index File but not one with wp-blog-header";
echo "\n\n";
//Go one directory up
$up_path = realpath($dir. DIRECTORY_SEPARATOR . '..');
get_wp_index($up_path);
}
} else {
echo 'No Index File Found';
echo "\n\n";
//Go one directory up
$up_path = realpath($dir. DIRECTORY_SEPARATOR . '..');
echo $up_path;
get_wp_index($up_path);
}
}
get_wp_index();
?>

define ffmpeg binaries path dynamically in php depending on OS

I'm trying to define the ffmpeg binaries path dynamically in php depending on OS...
Here's my code:
// Check if OS is Windows
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$OS = 'win';
// 'This is a server using Windows!';
}
require ABSPATH . '/vendor/autoload.php';
if($OS == 'win')
{
$ffmpegpath = ABSPATH . 'FFMpeg/bin/ffmpeg.exe';
$ffprobepath = ABSPATH . 'FFMpeg/bin/ffprobe.exe';
}
$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => $ffmpegpath,
'ffprobe.binaries' => $ffprobepath,
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
));
For some reason it doesn't work.
If I hard code the same paths within the ffmpeg construct function it does work.
Any ideas?
Thanks.
Nevermind, I found the problem, it was a pesky little GLOBAL var bug in my code.
Apologies for the question, I can't delete it.
Thanks.

command line combine pdfs through php exec

I just setup wkhtmltopdf to take html docs and turn them into pdfs but now I need a way to combine the multiple pdfs.
Any suggestions?
We do have pdflib license if there is something it can do but seems its mainly an api for custom building pdfs.
If you got wkhtmltopdf I suppose you're using Linux and you got a root shell access.
You could use Pdftk Toolkit via system() or exec().
First install it. It's a package in Debian/Ubuntu, for example:
sudo apt-get install pdftk
Then make sure that's visible in your bin search PATH.
And a simple PHP snippet:
// In / Out filenames
$input_files = array( 'file_one.pdf', 'file_two.pdf' );
$file_out = 'merged.pdf';
// Escape names and create argument
$line_parts = '';
foreach( $input_files as $file ) {
$line_parts .= escapeshellarg( $file ) . ' ';
}
// Run pdftk
$cmd = 'pdftk ' . $line_parts . ' cat output ' . escapeshellarg( $file_out );
system( $cmd, $retval );
if( $retval ) { print 'There was an error!'; }

Categories