开发者

Problem with named pipes breaking php/windows

开发者 https://www.devze.com 2023-03-15 02:11 出处:网络
I have a named pipe being read by a python program, installed as a service in Windows 2008 to print data from a database. The code (php) that writes to the pipe is as follows. ($cmd is the command lin

I have a named pipe being read by a python program, installed as a service in Windows 2008 to print data from a database. The code (php) that writes to the pipe is as follows. ($cmd is the command line passed)开发者_StackOverflow社区.

$pipeName = "\\\\.\\pipe\\printerpipe";
@trigger_error("");
@$pipe = fopen($pipeName,'rb+');
$a = error_get_last();
if ($a['message'] == '') {
    fwrite($pipe,$cmd);
    $ans = fread($pipe,256);
} else {
    print error message "service not loaded"        
}

There is no custom error handler.

This has worked fine on my test machine (Window7) and on the production server - until today. Today it printed three reports, then reported the service not loaded error, and then printed 4 times more! I doubt that the system was busy or overloaded - I have one user, the report is tiny (most reports are one page), and the printing is spooled. Most reports appear on the printer as the reply to the request is being rendered by the browser.

Also the link between my Python code and the metworked printer appers to break every night, so i have to restart the service every morning. Can someone confirm that this is due to the printer being switched off, or suggest how to re-establish the link, other than restarting the printing service?

I need to make the service reliable, and I don't know how to proceed. Ideas and advice gratefully recieved.

It could be this code - I don't understand the error handling, and the code was copied from a post on the internet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号