Skip to main content

Convert PHP serializer strings to JSON

Project description

Build status

A small library that aims to provide a fast way of decoding PHP serialization format. Use it if you need to migrate large amount of PHP data and performance is essential.

The library provides only one function:

>>> import php2json
>>> php2json.php2json(b's:3:"foo";')
b'"foo"'

It’s goal is to convert PHP serializer string into JSON string as fast as possible. The assumption is that JSON decoders (such as standard json module or ujson) are much better optimized than phpserialize.

Here’s a simple benchmark where I pit phpserialize against php2json combined with ujson and json:

phpserialize: 6.60s
php2json+ujson: 0.15s
php2json+json: 0.19s
speedup (ujson): 4337%
speedup (json): 3485%

Installation

Install with:

pip install php2json

Tests

Run test with:

pip install tox
make clean
tox .

Benchmark

Run benchmark with:

pip install -r requirements-test.txt
make bench

Limitations

Few limitations apply:

  • only deserialization is possible

  • PHP objects are not supported

  • behaviour is undefined in presence of unicode strings

  • input data must adhere to JSON standards, most notably: array keys must be strings or values easily convertible to strings (such as integers)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

php2json-0.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

php2json-0.2-cp36-cp36m-manylinux1_x86_64.whl (35.4 kB view details)

Uploaded CPython 3.6m

php2json-0.2-cp27-cp27mu-manylinux1_x86_64.whl (33.1 kB view details)

Uploaded CPython 2.7mu

File details

Details for the file php2json-0.2.tar.gz.

File metadata

  • Download URL: php2json-0.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for php2json-0.2.tar.gz
Algorithm Hash digest
SHA256 581c370c4b745e26c487e695b724b85d85041aff80bff234b9542bd8d8317c01
MD5 f5c2c7bce608db5913d9b67f0003350c
BLAKE2b-256 04605f22822ef526a48c6166edf1c346463fb6ec8dd314189604a4df5ff5878d

See more details on using hashes here.

File details

Details for the file php2json-0.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for php2json-0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 68c4d5fce14c5f4168bd854f6a9236c2afd2321566f18f69a61d87753943f811
MD5 1d9350c1b0658f25171c42564b4ae09a
BLAKE2b-256 a83079813746456829526d107af5c8d99d567a6cba16233e2b4b6f4461b3156e

See more details on using hashes here.

File details

Details for the file php2json-0.2-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for php2json-0.2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 707029466175d608afc4c1ac074d71e8f4e08798bd6cb9390bc621b939432662
MD5 588d1c83e64399fc202301090965869c
BLAKE2b-256 fdf0ebc89fd1fbd115b8defd3ff6bce8e634f2912bd571d0a23cfd0a68bece15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page