Сжатие с распаковкой Java с PHP

Это походит на то, что Вы хотите, один процесс, слушающий на для новых клиентов, и затем вручите от соединения, как только Вы получаете соединение. Чтобы сделать это через потоки легко, и в .NET у Вас даже есть BeginAccept и т.д. методы для заботы о большой инфраструктуре для Вас. Вручить от соединений через границы процесса было бы сложным и не будет иметь никаких преимуществ производительности.

, Кроме того, у Вас может быть несколько связанных процессов и слушающий на том же сокете.

TcpListener tcpServer = new TcpListener(IPAddress.Loopback, 10090);
tcpServer.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
tcpServer.Start();

while (true)
{
    TcpClient client = tcpServer.AcceptTcpClient();
    Console.WriteLine("TCP client accepted from " + client.Client.RemoteEndPoint + ".");
}

, Если Вы разжигаете два процесса каждое выполнение вышеупомянутый код, это будет работать, и первый процесс, кажется, получает все соединения. Если первый процесс уничтожается, второй тогда получает соединения. С сокетом, совместно использующим как этот, я не уверен точно, как Windows решает, какой процесс получает новые соединения, хотя быстрый тест действительно указывает на самый старый процесс, получая их сначала. Относительно того, совместно использует ли это, если первый процесс занят или что-либо как этот, что я не знаю.

10
задан h22 1 February 2013 в 18:08
поделиться

2 ответа

Try using DeflaterOutputStream instead of GZIPOutputStream

The PHP functions call into libzlib which implements DEFLATE. Gzip is a different beast entirely.

Naming the PHP functions gzXXX only adds to the confusion.

6
ответ дан 3 December 2019 в 20:43
поделиться

I just saw your question and was curious about it. So i made my own test-case. I left all the Servlet related stuff out of the problem and coded something like this:

import java.io.*;
import java.util.zip.GZIPOutputStream;

public class GZIPTestcase {

    public static void main(String[] args) throws Throwable {
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(new File("/Users/malax/foo2.gz")));
        PrintWriter pw = new PrintWriter(gzipOutputStream);

        pw.println("All your base are belong to us!");
        pw.flush();
        pw.close();
    }
}

The GNU gunzip was able to uncompress the data. Then i tries to uncompress it with PHP. It failed with the same error you got. I investigated further and found the following methods:

  • gzdecode()
  • gzinflate()

gzinflate does not work either, gzdecode is only shipped with PHP6 wich i havn't installed. Maybe you could try this. (According to http://bugs.php.net/bug.php?id=22123 this will work)

Im i doubt that the problem is on the Java side because GNU's gunzip can deflate the data so it must be correct. You might want to investigate further on the PHP side.

There is a realted question for .NET and PHP where the original poster has the same problem as you have: Can PHP decompress a file compressed with the .NET GZipStream class?. PHP does not seem to be able to decompress the data from the .NET equivalent of the GZIPOutputStream either.

Sorry that i dont have a "solution" but i might have pointed you in the right direction anyways.

EDIT: I found an entry in the PHP Bugtracker which explains the problem: http://bugs.php.net/bug.php?id=22967 Похоже, что gzuncompress не может распаковать данные GZIP с заголовками, которые будут созданы с помощью GZIPOutputStream. Как указано в записи Bugtracker, попробуйте обрезать заголовок.

9
ответ дан 3 December 2019 в 20:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: