I wrote a following short script in PHP:
<?
$s = socket_create(AF_UNIX,SOCK_STREAM,0);
socket_connect($s,"/tmp/tmpsock");
socket_write($s,"test");
socket_close($s);
>
I user this code to connect to a simple server that prints everything it receives onto terminal output.
The script works fine when I opened it from terminal using php index.php, however I want it to be a part of a webapp, and I try to run it on apache2 server opening the index.php page in web browser (on server of course). The script doesn't work then - the socket_connect function returns nothing, the error description is "Success()" and the message doesn't appear on server.
I use Ubuntu 16.04, Apache 2.4 and PHP 7.0
Related
I just started with php and I installed my xampp and got it running. Now I wanna run my code that I have, its a simple print function but when I try running it, I see the code appear in Chrome an not the print. this is what I have in my code: <?php echo "Hello World!"; ?> and when I try to run it I get the exact same thing on chrome
You should start apache and MySQL if you are connecting to DB on XAMPP then put your script in the htdocs folder then you can run your code by going to http://localhost
Another solution is by running this command to start a php server
php -S 127.0.0.1:8000 index.php
I have a Windows Server 2016 VPS with Plesk and PHP 7.1x.
I am trying to execute a simple AutoHotKey script from PHP using the following command:
<?php shell_exec('start /B "C:\Program Files\AutoHotkey\AutoHotkey.exe" C:\inetpub\vhosts\mydomain.com\App_Data\myahkscript.ahk'); ?>
This is the only line on the page. I have tried different ahk scripts, the current one simply creates a MsgBox.
When I execute my php page, on VPS Task Manager I see three processes created with the expected USR: cmd.exe, conhost.exe and php-cgi.exe. However, my PHP page just sits waiting on the server and nothing actually happens on the server.
I have also tried the same line except replacing shell_exec with exec. This seems to make no difference. I have tried without start /b with both commands. In that case the PHP page completes but no new processes are started.
I cannot find any errors in any logs: Mod_Security, Plesk Firewall, IIS.
Any ideas?
EDIT:
I tried my command from the VPS command prompt and immediately slapped in the face with the obvious issue of the space in 'Program Files'. I quoted the string as shown above and the command works. This eliminated the hang when running from PHP. However, the command still does nothing when executed from the web page.
EDIT:
Based on suggestions from the referenced post 'debugging exec()':
var_dump: string(0)""
$output: Array()
$return_val: 1
One point was that I would probably not be able to invoke GUI applications. That puts a damper on the idea.
I experience problem with PHP request on self. In example I will use file_get_contents() but same happen for exec('wkhtmltopdf [*SELF*]') or curl()
lets name my server example.com
apache2 installed
FastCGI (multiple PHP versions 5.3, 5.4, 5.5, 5.6, 7.0)
now I have 2 dummy scripts
1st script
//get-html.php
file_get_contents('http://example.org/index.html')
2nd script
//get-php.php
file_get_contents('http://example.org/index.php')
Testing
1) command-line: php get-html.php // Success
2) browser: example.org/get-html.php // Success
1) command-line: php get-php.php // Success
2) browser: example.org/get-php.php // Timeout
What I tried next
create subdomain like subdomain.example.org/index.php to have differet PHP version for get-php.php and for index.php
amend /etc/hosts
request on other sites (like google.com) // Success
session_write_close() before file_get_contents() and session_start() right after does not work also
So my suspect is mod_fastcgi. It seems like the apache is not able to run 2 instances of this to handle PHP requests which comes from itself. As running script from command line works as expected.
Does anybody have any advice?
I did not set PHP_FCGI_CHILDREN what is in default 1.
When I called in PHP script another PHP script from my server over apache it failed as it was not able to create another PHP FCGI instance.
I'm trying to execute a PHP script from my apache webserver. I tried a Hello World page and it worked, but when I run this findmyiphone script, it shows 500 error from the webserver. What's wrong?
I tried to execute the example.php in terminal by doing php -f example.php, how would I do that from a browser in my web server
Answer is I need to restart the server
I have installed WAMP server 2.0 with (PHP 5.4.3). After installing WAMP I have restarted all the services and can open
phpinfo() - it is showing up fine
phpmyadmin - it is also showing up fine.. i can play with database..
however when run simple php file in chrome I could see the code rather than result. below is the code i am trying..
<?php
echo "hello world";
?>
below is the link to file which I am trying to access via chrome.
file:///C:/WAMP/www/hello%20world.php
Make sure you have started apache
Try http://localhost/hello_horld.php
To run this script, start a browser use URL http://localhost/your_file.php or http://127.0.0.1/your_file.php
PHP is a server-side technology (instead of client-side technology like JavaScript). The PHP statements <?php ... ?> are processed in the server, and the results returned to the client (browser). so you need to use it through server not direct