I'm currently using proc_open() in php to communicate with command line tools. It automatically creates up to 3 file descriptors for STDIN, STDOUT and STDERR because more than 3 pipes breaks Windows compatibility. It works great on Windows XP and 10.7 on my Mac.
However, I would like to be able to create my own named pipes for better control. If I'm unable to do so, then I have to maintain references between the process resource and its stream resources, which is overly complicating my code. I can't use files because they fill up disk space for long tasks. I'm also trying to avoid using sockets because they aren't enabled by default in php.
Here are the links I have found so far:
http://bytes.com/topic/php/answers/557245-named-pipes-windows
https://bugs.php.net/bug.php?id=29005
Interprocess Communication using Named Pipes in C# + PHP
http://en.wikipedia.org/wiki/Named_pipe#In_Windows
http://www.phpkode.com/source/p/xp-framework/xp-framework-xp-framework-554d8b2/core/src/main/php/rdbms/mysqlx/NamedPipe.class.php
I've tried each of these in php 5.3.13 but none of them work:
var_dump(fopen("\\\\.\\pipe\\mypipe", "w+"));
var_dump(fopen("\\\\127.0.0.1\\pipe\\mypipe", "w+"));
var_dump(fopen("\\\\".php_uname('n')."\\pipe\\mypipe", "w+"));
I always get an error that looks like this:
PHP Warning: fopen(\\.\pipe\mypipe): failed to open stream: No such file or directory in C:\Documents and Settings\Administrator\Desktop\named-pipe.php on line 15
PHP Stack trace:
PHP 1. {main}() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:0
PHP 2. fopen() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:15
Warning: fopen(\\.\pipe\mypipe): failed to open stream: No such file or directory in C:\Documents and Settings\Administrator\Desktop\named-pipe.php on line 15
Call Stack:
0.0018 431936 1. {main}() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:0
0.0018 432072 2. fopen() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:15
bool(false)
So my question is, has anyone successfully opened a named pipe on Windows XP? If not, what versions of Windows support named pipes? I don't know if the pipe "file" descriptor needs to already exist, for example if it has to be created by mysql or other services.
Bonus points if you can supply cross-platform code, perhaps using posix_mkfifo() or system("mkfifo pipe") like in this answer:
http://www.php.net/manual/en/function.popen.php#22801
Ideally the solution should work with a vanilla install of php, so without sockets, etc, but anything helps thanks.
Have you realy read http://bytes.com/topic/php/answers/557245-named-pipes-windows ?
The solution is not to use dots in pipe's name.
All your samples are with dots in pipe's name.
Is this server code you are writing? It looks like you're using the client side calls perhaps you need to create the pipe first?
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365590(v=vs.85).aspx
Not sure you can write the server in php, needs CreateNamedPipe().
Related
When creating a scheduled task to run a php script in Plesk Onyx on windows it results in an error.
However when i run the same script in the browser it works without any issues.
I have been looking for the permission settings in the webroot and set them to allow access to all user groups on the server.
The error i get is the following:
Warning: require(\pcp2\inc\db_config.php): failed to open stream: No such file or directory in D:\www\domain\pcp2\conversion\addBooking.php on line 5
Fatal error: require(): Failed opening required '\pcp2\inc\db_config.php' (include_path='.;.\includes;.\pear') in D:\www\domain\pcp2\conversion\addBooking.php on line 5
Line 5 contains the following info:
require($_SERVER['DOCUMENT_ROOT']."\pcp2\inc\db_config.php");
It's failing becasue $_SERVER['DOCUMENT_ROOT'] is a value provided by the web server, and is thus undefined when run without a web server (i.e., from the command line.) You'll need to provide an alternative mechanism to set the base directory.
You might use relative paths:
require("pcp2\inc\db_config.php");
Or absolute paths based on the magic constant __DIR__. (This assumes the script doing the require'ing is in the document root directory.)
require(__DIR__."\pcp2\inc\db_config.php");
Ideally however, you're better off using PSR-4 namespacing with an autoloader.
I have recently set up XAMPP. The setup was straightforward but I don't seem to know the correct tweak to allow it to speak to the outside web world.
No matter how I try to read an external URL, it tells me where to get off.
(In PHP) I've tried the simple file_get_contents route. When that failed, somebody pointed me to curl. I enabled that in php.ini but that failed too.
I get the very unhelpful "Unable to open file"
Fatal error: Unable to open "https://earth.esa.int/documents/10174/1514862/Swarm_Level-2_TEC_Product_Description" in C:\xampp\htdocs\includes\PdfToText.phpclass:1665 Stack trace: #0 #2 {main} thrown in C:\xampp\htdocs\includes\PdfToText.phpclass on line 1665
I know this seems like an error with the class PdfToText (above) but it's just a way of showing the error. Take the file from between the quote marks, try to load it and it's fine. It doesn't want to open files from the outside world no matter what's tried.
I assume that it's a port/proxy/something but I've Googled all day in and out of stackoverflow and I cannot see the same problem anywhere.
Quick fix:
Find your php.ini file:
php -i | grep "Loaded Configuration File"
look for allow_url_fopen and set it to On
allow_url_fopen = On
Explanation:
This error happens because when you use functions like file_get_contents or fopen, you are handling file pointers, what allow_url_fopen will let you do is, resolve the url, create a tcp connection and create a network file pointer to that tcp connection, which will be handled by php as it were a file.
For security reasons, this setting is disabled on some installations.
Check the docs:
http://php.net/manual/en/filesystem.configuration.php
The error in question:
[RuntimeException]
Error Output: PHP Warning: require(/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php): failed to open stream: N
o such file or directory in /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload_real.php on line 58
PHP Stack trace:
PHP 1. {main}() /home/admin/web/"webpage"/public_html/test/artisan:0
PHP 2. require() /home/admin/web/"webpage"/public_html/test/artisan:16
PHP 3. require() /home/admin/web/"webpage"/public_html/test/bootstrap/autoload.php:17
PHP 4. ComposerAutoloaderInit95cd02d44d232a8b8d6e5e52544d8647::getLoader() /home/admin/web/"webpage"/public_html/test/vendor
/autoload.php:7
PHP 5. composerRequire95cd02d44d232a8b8d6e5e52544d8647() /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload
_real.php:49
PHP Fatal error: require(): Failed opening required '/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php' (includ
e_path='/home/admin/web/"webpage"/public_html/test/vendor/phpunit/php-text-template:/home/admin/web/"webpage"/pub
lic_html/test/vendor/phpunit/php-timer:.:/usr/share/pear:/usr/share/php') in /home/admin/web/"webpage"/public_html/test/vendor
/composer/autoload_real.php on line 58
PHP Stack trace:
PHP 1. {main}() /home/admin/web/"webpage"/public_html/test/artisan:0
PHP 2. require() /home/admin/web/"webpage"/public_html/test/artisan:16
PHP 3. require() /home/admin/web/"webpage"/public_html/test/bootstrap/autoload.php:17
PHP 4. ComposerAutoloaderInit95cd02d44d232a8b8d6e5e52544d8647::getLoader() /home/admin/web/"webpage"/public_html/test/vendor
/autoload.php:7
PHP 5. composerRequire95cd02d44d232a8b8d6e5e52544d8647() /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload
_real.php:49
Background: Was developing locally, got to the point where I wanted to have a staging site. Set up the staging site on digital ocean (entOS 6.5 x64). I then cloned my git repo into my desired folder - configured vhosts DefaultDirectory to my public path.
A default installation works, composer update/install works. However, with my cloned repository I am getting said error. '/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php' is a file I made with some helper methods I could use in various controllers. It has not caused any problems locally. I can composer update/install locally, without any problems.
Any guidance would be greatly appreciated!
Are those literal quotation marks in your file path
/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php
Or are you just using that to indicate your website name normally goes there? If the former, I'd consider not doing that as it's pretty weird to have quotes in unix file names, and you may run into problems based on assumptions other people have made.
Regardless -- you have the information you need
[RuntimeException] Error Output: PHP Warning: require(/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php): failed to open stream: N o such file or directory in /home/admin/web/"webpage"/public_html/test/vendor/composer/autoload_real.php
PHP is telling you it tried to require in a specific file
/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php
but it could not find it ("failed to open stream"). This means either the file doesn't exist on the computer you're trying to load it from, or PHP can't see it for some reason (try dumping the results of is_readable('/home/admin/web/"webpage"/public_html/test/app/Http/helpers.php'); to see if PHP thinks it can read the file or not.
For the longest time now I've been trying to convert HTML pages containing large tables to PHP. These are styled with CSS and can be several pages long.
I first tried DOMPDF. It works great, until a document is more than one page. None of the fixes I've found work. Either it errors out, or any element that would be even partially on the second page gets lumped over the content of page 1. I've tried both the latest release and the SVN copy I checked out today.
I also tried html2ps/pdf, and it gives me "permission denied" errors writing to the cache directory, even though the directory is fully writable. The system requirements test script passes. The server is running PHP 5 under IIS (not my choice heh).
Can either of these be convinced to work, or is there a library that can do it?
Errors from the demo/test scripts:
Warning: file_put_contents(C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/7d888258e9745b3716532ea81342daaf.css.compiled) [function.file-put-contents]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\JM\pdf\html2ps\css.cache.class.php on line 33
Warning: fopen(C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/unicode.lb.classes.dat) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\JM\pdf\html2ps\inline.content.builder.php on line 991
Warning: flock() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\JM\pdf\html2ps\inline.content.builder.php on line 992
Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\JM\pdf\html2ps\inline.content.builder.php on line 1011 (this error repeats several thousand times)
Warning: fopen(C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/times.z) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\JM\pdf\html2ps\pdf.fpdf.makefont.php on line 318
Can't write to file C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/times.z
A similar problem with html2pdf under IIS has been discussed here.
The solution was quite simple, yet weird. If this doesn't help you, a full error-message and / or a little bit of code would help me to help you.
I personally recommend command line applications instead of any PHP libraries.
Reasons :
PHP libraries need more time and memory (cache) for conversion process.
They need well-formatted HTML pages only, otherwise throw errors or warnings.
No support for external style sheets.
Command Line Tool:
If you run your script on a Linux server then I suggest command line tools.
Reasons :
They are extremely fast compared to PHP libraries.
Support CSS.
Accept non-well-formatted HTML.
Which command line tool to use?
wkhtmltopdf
htmltopdf
html2pdf
For more information refer to Converting HTML to PDF (not PDF to HTML) using PHP.
I wanted to create search engine for my webpage, but during indexing on server it crashes with errors :
Warning: opendir(/admin/lucene/) [function.opendir]: failed to open dir: Too many open files in /admin/includes/Zend/Search/Lucene/Storage/Directory/Filesystem.php on line 159
Warning: readdir(): supplied argument is not a valid Directory resource in /admin/includes/Zend/Search/Lucene/Storage/Directory/Filesystem.php on line 160
Warning: closedir(): supplied argument is not a valid Directory resource in /admin/includes/Zend/Search/Lucene/Storage/Directory/Filesystem.php on line 167
Fatal error: Ignoring exception from Zend_Search_Lucene_Proxy::__destruct() while an exception is already active (Uncaught Zend_Search_Lucene_Exception in /admin/includes/Zend/Search/Lucene/Storage/File/Filesystem.php on line 66) in /admin/test.php on line 549
I am using newest version of ZF. Is there code solution for such error - I run script on localhost and it works great.
Thanks for any help.
It seems the problem is in the large number of segments in the index.
Could you check how much files does index folder contain?
There are two ways to solve this problem:
a) Optimize index more often.
b) Use another MaxBufferedDocs/MergeFactor parameters. See Zend_Search_Lucene documentation for details.
If it doesn't help, please register JIRA issue for the problem.
PHP has hit the limit on the number of files it can have open at once it seems might be an option to change in php.ini, could be an OS (quota) limit or you might be able to tell the indexer to slow down and not have so many files open simultaneously.
This is most definitely a Linux/kernel imposed limitation. Use the following command as root on your machine:
cat /proc/sys/fs/file-nr
Return values are defined as:
Total allocated file descriptors
Total free allocated file descriptors
Maximum open file descriptors
I'm also going to take a guess and say you are on a shared hosting machine. If this is the case, I imagine that this sort of issue may come up frequently.
Finally, the following article provides a good amount of information on Linux and open file descriptors even if it is a little dated.
http://www.netadmintools.com/art295.html