I've got the following code and the semaphore wouldn't lock it as expected.
(I'm aware of apc_inc. This is not what I'm looking for.)
$semkey = sem_get(123);
sem_acquire($semkey);
$count = apc_fetch('count111');
if(!$count) $count = 0;
$count++;
apc_store('count111', $count);
sem_release($semkey);
followed by
ab -n 4000 -c 200 http://localhost/test.php
0 requests failed.
but after that an apc_fetch('count111') shows only ~ 1200 hits
nginx on ubuntu 12.04 (64bit), php 5.3.16~dotdeb, php-fpm
update 1: works perfectly on Linux mint, 5.4.6~dotdeb, built in web server. I'm going to try the same machine with the same version with nginx.
The problem was, apparently, with the APC itself, not with the semaphore.
Updating to PHP 5.4.8-1~dotdeb.0 has solved the problem for both nginx and built-in server test runs.
Related
I'm running Windows 10, with a WSL2 Ubuntu instance. I do my development within the WSL2 instance with the "Remote - WSL" extension of Visual Studio Code. So my VSC is running as a WSL2 application, not as a Windows application. I have an additional remote server (I'll refer to this as "Server X" which actually hosts/runs the PHP code. This remote server does not support the use of the "Remote - WSL" extension, so I use an "SFTP" extension to push my changes to this server. And I cannot run the code locally (in either Windows or WSL2) due to the database connection being unsupported.
I'm trying to configure remote debugging of the code on Server X from within VSC running as a WSL2 application (IE: using the "Remote - WSL" extension). The intent is to listen for a browser request to initiate the debug session.
What's happening is when I turn on "Listen for Remote Connection" in VSC when running as a WSL2 application, it doesn't detect the browser when I refresh it. I've determined the reason is because while running as a WSL2 application, my IP is different than when I'm outside WSL (which is where I'm refreshing the browser). So in short, I'm initiating a browser session outside of WSL (IP: 192.168.1.2), the remote server attempts to connect to a debugger at 192.168.1.2:9003, but doesn't find one because my VSC is listening on 192.168.1.3:9003 while it's running as a WSL2 application.
I've confirmed if I instead run VSC as a Windows application (IE: not using Remote - WSL extension on WSL2 instance) everything works fine after adjusting some setting paths to point to Windows PHP rather than WSL2 PHP.
I've been trying to play around with using SSH tunnels to re-route my port 443 traffic from Windows through WSL, but have been unsuccessful so far.
Has anyone run into this issue and have any idea how to get around it? Or is what I'm trying to do unsupported/discouraged?
So WSL runs under the 172.16. 0.0/12 private address range and is not directly accessible by anything external to the host Windows machine. As such, populating xdebug.client_host with this IP, will not work.
My initial idea of using port forwarding was correct, but not in the direction I thought. Instead of redirecting the outgoing web traffic (443 since my site is using SSL) from Windows through WSL, then redirect from WSL to Server X. I instead just needed to redirect the incoming xdebug traffic (9003) from Windows to WSL. (Probably what #Derick was alluding to)
To do this, I left xdebug configured as it normally would have been if WSL wasn't in the picture.
So:
zend_extension=xdebug
xdebug.mode=profile,debug
xdebug.idekey=<ide key value here>
xdebug.client_host=<ip of windows host, as backup>
xdebug.start_with_request=trigger
xdebug.trigger_value=<my trigger value>
xdebug.discover_client_host = 1
Then, using the following PowerShell script on the Windows host to redirect port 9003 from the Windows host to the WSL guest:
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if ($found) {
$remoteport = $matches[0];
}
else {
Write-Output "IP address could not be found";
exit;
}
$ports = #(9003);
for ($i = 0; $i -lt $ports.length; $i++) {
$port = $ports[$i];
Invoke-Expression "netsh interface portproxy delete v4tov4 listenport=$port";
Invoke-Expression "netsh advfirewall firewall delete rule name=$port";
Invoke-Expression "netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteport";
Invoke-Expression "netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port";
}
Invoke-Expression "netsh interface portproxy show v4tov4";
Above script is modified from the script found here:(https://dev.to/vishnumohanrk/wsl-port-forwarding-2e22)
Which itself is modified from here: (https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723)
Note*: You have to install net-tools in the WSL guest in order for the above script to work, so: sudo apt install net-tools.
I installed python 2.7 and the Goole Cloud SDK.
After that I installed the php runtime using this command :
gcloud components install app-engine-php-windows
I then boot up a local dev server using this line :
dev_appserver.py <app-directory>
The server boots up fine, but when I send multiple requests to the server, I see multiple popups (one after te other) saying "CGI / FastCGI has stopped working". I can then "Debug" or "Close program".
In the logfile I see this :
ERROR:root:php failure (255) with:
stdout:
ERROR:root:php failure (-1073741819) with:
stdout:
OS specifics : Windows 10 Pro 64-bit.
Also, adding extension="php_curl.dll" to php.ini does not avoid my problem as stated in other issues similar to this one.
Can anyone help with this issue?
PHP runs so slowly on my Windows desktop that phpMyAdmin takes minutes to open a database. Here’s a comparison of the time to run a simple PHP test program:
Windows 8.1 machine running XAMPP: 3597 ms
iPage shared hosting: 65 ms
A2Hosting shared hosting: 26 ms
Here’s the test program…
<?php
$rStartTime = microtime(true);
$countTo = 100000;
$a = 0;
//$countTo = $countTo * 100;
for ($x = 0; $x <= $countTo; $x++) {
$a = sqrt(pow($x, 2));
}
$rMs = floor((microtime(true) - $rStartTime) * 1000);
echo 'timer done, countTo=' . $a . ' ms=' . $rMs;
The test program is run without debugging, by entering "http://localhost/timer.php" into Firefox.
The local machine is normally blazing fast. It’s running…
Windows 8.1
XAMPP 1.8.3 (control panel v3.2.1)
Apache 2.4.4 (latest is 2.4.20)
PHP 5.5.3
Antimalware = Windows Defender
IDE = PHPStorm 10.0.2
What's making PHP run so slowly?
I found the problem was Xdebug in xampp\php\php.ini. Here're the results of trying many solutions found around the web:
Run XAMPP as adminisrator and restart server: 3617 ms
In xampp/apache/conf/httpd.conf, replace localhost with 127.0.0.1 and restart server: 3639 ms
In Windows/System32/drivers/etc/hosts, add “127.0.0.1 127.0.0.1” & “127.0.0.1 localhost” and restart Windows: 3960 ms
In Windows/System32/drivers/etc/hosts, un-comment “127.0.0.1 localhost” and restart Windows: 3659 ms
In php.ini, uncomment zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll" and restart server: 3643 ms
In php.ini, set xdebug.remote_enable=0: 3598 ms
In php.ini, set remote_host="localhost": 3593 ms
In php.ini, set xdebug.profiler_enable=0: 249 ms
In php.ini, comment out all Xdebug statements: 27 ms - Success!
The sad part is, I make mistakes and need Xdebug :-(
I solve my problem with xdebug idekey setting (xdebug.idekey="xdebug1"), and chrome extension xdebug helper (https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc)
*Dont forget to disable remote_autostart (xdebug.remote_autostart=0)
Only activating debug (xdebug) by request, using idekey setting, so if debug not needed php processing can be faster/normal, tonggle by button with chrome extension
I'm using xampp 1.8.3 on windows 10 64bit,
i use custom idekey, xdebug.idekey="xdebug1", same with xdebug helper setting
[XDebug]
zend_extension = "E:\xampp183\php\ext\php_xdebug.dll"
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "E:\xampp183\tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_autostart=0
xdebug.idekey="xdebug1"
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.trace_output_dir = "E:\xampp183\tmp"
xdebug.remote_log="E:\xampp183\tmp\xdebug\xdebug.log"
Now breakpoint/debug activated only if session is requsted via xdebug helper
I excluded my website folder and my xampp folder in Windows Defender and things were solved here.
I Had the same problem with xampp, and the problem was WINDOWS DEFENDER, if you disable the windows defender protection, xampp is faster (normal speed), Also you can search the xampp folder as exlusion in windows defender. these is the solution.
Running the TS (Thread Safe) version of php can slow things down a lot. TS is generally never needed, so use a NTS (Non-Thread Safe) version of php.
[Edit addition, stolen from Quora]
Thread Safe (TS) and Non-Thread Safe (TS) are the two different PHP builds available.
Thread-safety ensures that when the shared data structure is manipulated by different threads, it is free from race conditions. This version is recommended where the web server run multiple threads of execution simultaneously for different requests.
For example, in Apache server, if we use mod_php as worker MPM, thread-safe version should be used.
Non-thread-safe version on the other hand is used where PHP is installed as a CGI binary. Here every request is handled separately which removes the need of thread-safe version. Moreover, using thread-safe version here degrade the performance due to unnecessary checks for thread safety. Servers like IIS & NGINX do not need thread safe versions.
I figured out that Eclipse did not end a XDebug session properly. I solved the problem by restarting the debug session and ending it properly.
for me has been an improvement after changing all of above to change from https://localhost to https://127.0.0.1
For chrome users: I found out (after trying all hints above) that the Chrome extension "Evernote Web Clipper" is also slowing down chrome.
When loading a plain URL without any includes:
enabled / disabled Evernote Web Clipper: 0,7ms / 0,25ms
For me, mcAfee Web boost extension was the Blocker. I removed the extension and now it speeds up by 90%
If you are using mysql db within your PHP script, pls check your db connection config.
Use 127.0.0.1 instead of localhost in case of db host on windows (10).
Solved php - WAMP/XAMPP is responding very slow over localhost / wordpress
The easiest way is that go to c dirive > xamp > php folder > search php.ini > clink on top then find max_execution_time anset it to max_execution_time=300 > now restart xamp > all done :)
max_execution_time=300
I am trying to run a PowerShell command from inside a php file on my webserver.
Here is my php code:
<?php
$query = shell_exec('C:\\Windows\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe -command Get-Host');
echo $query;
?>
The result I get is HTTP Error 500 - C:\PHP\php-cgi.exe - The FastCGI process exceeded configured activity timeout - Error Code 0x80070102
To perform a test to verify shell_exec and php were functioning (that I hadn't screwed something up when setting up the environment). I also tried this php:
<?php
$query = shell_exec('dir c:\\');
echo $query;
?>
This worked, the page source looked exactly like you'd expect if you had run the dir c:\ command from a command prompt in windows.
I've looked at several other articles here on stackoverflow, as well as on technet, and can't seem to identify what is causing this to time out. When I run the same command from the command prompt the result is very quick.
Here are the results from executing the same command manually at the command prompt (again what you'd expect):
C:\>C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -command Get-Host
Name : ConsoleHost
Version : 2.0
InstanceId : 9a24a372-f0a3-4a79-b9fd-1e180e9a8069
UI : System.Management.Automation.Internal.Host.InternalHostUserI
nterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
A little about my environment:
I'm running IIS 7.5 on a Windows 2008 R2 SP1 Standard Server.
The server is standalone (not part of a domain).
I have PHP 5.5.9 installed, and working. phpinfo() returns the expected page without any noticeable errors.
Any help in getting me on track with executing powershell commands from php is much appreciated!
Try this :
$query = shell_exec('C:\\Windows\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe -command Get-Host < NUL');
My dev server is Debian Squeeze and I'm running Gearman 1.1.5 which I compiled from source along with the php pecl extension v1.1.1
If I run the reverse_client.php script I get the GEARMAN_COULD_NOT_CONNECT error.
PHP Warning: GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430 in /home/bealers/build/gearman-1.1.1/examples/reverse_client.php on line 26
There are a few similar posts on here about this and they all point to GM not running.
It is definitely running.
I'm starting it with these params:
PARAMS="--queue-type=MySQL --mysql-db=test_db --mysql-user=gearman --mysql-password=gearman"
If I drop the gearman_queue table in test_db then restart the daemon the table is recreated, so its mysql connection is fine and it's clearly starting.
I can also telnet to 4730 on localhost, so there's no firewall issue.
Initially GM had problems starting because it was starting before mysql, so I edited the init script
### BEGIN INIT INFO
# Provides: gearman-job-server
# Required-Start: $network $remote_fs $syslog mysql
and an update-rd.c gearman-job-server defaults sets it to start after and it starts fine on boot up now.
The only other thing I can think of is that initially I'd installed via apt but the version was to old so I removed it and compiled from source. /usr/sbin/gearmand no longer exists the only version is /usr/local/sbin/gearmand
ps ax | grep gearman shows only one process running.
Netstat shows only one process running`
tcp 0 0 *:4730 *:* LISTEN 2325/gearmand
The PECL lib seems fine:
php -i | grep gearman
/etc/php5/cli/conf.d/gearman.ini,
gearman
gearman support => enabled
libgearman version => 1.1.5
I'm out of ideas
I had the same problem and recently solved them after a couple days of frustration (hard to troubleshoot since there are three processes to worry about :-)
It appears (at least in my case) that the PHP documentation for GearmanClient::addServer() and GearmanWorker::addServer() is incorrect. Specifically, the docs seem to imply that hostname and port number are optional and that it will use localhost and port 4730 as defaults if you do not specify them. This never works - it suddenly occurred to me today to try explicitly specifying them for both client and worker processes and everything started working.
Try specifying all values for hostnames and ports and see if this works for you.
In case if you have used something like this
$client->addServers('127.0.0.1', 4730);
or
$client->addServers();
use something like this
$client->addServers('127.0.0.1:4730');
PS - I have used localhost IP, this can be replaced with actual host IP.
In my case it's little different. I got this same error when I had my addServer code inside the loop.
$client = new GearmanClient();
for ($i=0; $i<100000; $i++) {
$client->addServer("127.0.0.1", 4730);
$data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
$client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();
And this fixed it for me:
$client = new GearmanClient();
$client->addServer("127.0.0.1", 4730);
for ($i=0; $i<100000; $i++) {
$data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
$client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();
May be this could help someone.
If you want to use single server, you can use
$client->addServer($host, $port)
e.g. $client->addServer('127.0.0.1', 4730)
http://php.net/manual/en/gearmanclient.addserver.php
If you want to use multiple server, then you can use
$client->addServers($host1:$port1, $host2:$port2, $host3:$port3)
e.g. $client->addServers('127.0.0.1:4730', '127.0.0.2:8080')
http://php.net/manual/en/gearmanclient.addservers.php