php_process 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/php_process.rb +18 -23
- data/php_process.gemspec +2 -2
- data/spec/php_process_spec.rb +24 -0
- metadata +67 -72
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/php_process.rb
CHANGED
@@ -3,6 +3,7 @@ require "tsafe" if !Kernel.const_defined?(:Tsafe)
|
|
3
3
|
require "php-serialize4ruby"
|
4
4
|
require "base64"
|
5
5
|
require "open3"
|
6
|
+
require "thread"
|
6
7
|
|
7
8
|
#This class starts a PHP-process and proxies various calls to it. It also spawns proxy-objects, which can you can call like they were normal Ruby-objects.
|
8
9
|
#===Examples
|
@@ -37,6 +38,7 @@ class Php_process
|
|
37
38
|
@args = args
|
38
39
|
@debug = @args[:debug]
|
39
40
|
@send_count = 0
|
41
|
+
@send_mutex = Mutex.new
|
40
42
|
|
41
43
|
@responses = Tsafe::MonHash.new
|
42
44
|
|
@@ -276,12 +278,16 @@ class Php_process
|
|
276
278
|
def send_real(hash)
|
277
279
|
$stderr.print "Sending: #{hash[:args]}\n" if @debug and hash[:args]
|
278
280
|
str = Base64.strict_encode64(PHP.serialize(hash))
|
279
|
-
@stdin.write("send:#{@send_count}:#{str}\n")
|
280
|
-
id = @send_count
|
281
|
-
@send_count += 1
|
282
281
|
|
283
|
-
#
|
284
|
-
|
282
|
+
#Find new ID for the send-request.
|
283
|
+
id = nil
|
284
|
+
@send_mutex.synchronize do
|
285
|
+
id = @send_count
|
286
|
+
@send_count += 1
|
287
|
+
end
|
288
|
+
|
289
|
+
@responses[id] = Queue.new
|
290
|
+
@stdin.write("send:#{id}:#{str}\n")
|
285
291
|
|
286
292
|
#Then return result.
|
287
293
|
return read_result(id)
|
@@ -289,23 +295,12 @@ class Php_process
|
|
289
295
|
|
290
296
|
#Searches for a result for a ID and returns it. Runs 'check_alive' to see if the process should be interrupted.
|
291
297
|
def read_result(id)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
raise "#{resp["msg"]}\n\n#{resp["bt"]}"
|
299
|
-
end
|
300
|
-
|
301
|
-
$stderr.print "Found answer #{id} - returning it.\n" if @debug
|
302
|
-
return read_parsed_data(resp)
|
303
|
-
end
|
304
|
-
|
305
|
-
check_alive
|
306
|
-
sleep 0.01
|
307
|
-
$stderr.print "Waiting for answer to ID: #{id}\n" if @debug
|
308
|
-
end
|
298
|
+
$stderr.print "Waiting for answer to ID: #{id}\n" if @debug
|
299
|
+
resp = @responses[id].pop
|
300
|
+
@responses.delete(id)
|
301
|
+
raise "#{resp["msg"]}\n\n#{resp["bt"]}" if resp.is_a?(Hash) and resp["type"] == "error"
|
302
|
+
$stderr.print "Found answer #{id} - returning it.\n" if @debug
|
303
|
+
return read_parsed_data(resp)
|
309
304
|
end
|
310
305
|
|
311
306
|
#Checks if something is wrong. Maybe stdout got closed or a fatal error appeared on stderr?
|
@@ -357,7 +352,7 @@ class Php_process
|
|
357
352
|
$stderr.print "Received: #{id}:#{type}:#{args}\n" if @debug
|
358
353
|
|
359
354
|
if type == "answer"
|
360
|
-
@responses[id]
|
355
|
+
@responses[id].push(args)
|
361
356
|
elsif type == "send"
|
362
357
|
if args["type"] == "call_back_created_func"
|
363
358
|
Thread.new do
|
data/php_process.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{php_process}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
12
|
-
s.date = %q{2012-
|
12
|
+
s.date = %q{2012-10-17}
|
13
13
|
s.description = %q{Spawns a PHP process and proxies calls to it, making it possible to proxy objects and more.}
|
14
14
|
s.email = %q{k@spernj.org}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/php_process_spec.rb
CHANGED
@@ -151,6 +151,7 @@ describe "PhpProcess" do
|
|
151
151
|
|
152
152
|
#Send argument 'kasper' which will be what "$callback_from_php" will be changed to.
|
153
153
|
func.call("kasper")
|
154
|
+
sleep 0.1
|
154
155
|
raise "Expected callback from PHP to change variable but it didnt: '#{$callback_from_php}'." if $callback_from_php != "kasper"
|
155
156
|
|
156
157
|
|
@@ -162,6 +163,29 @@ describe "PhpProcess" do
|
|
162
163
|
raise "Cache count should be below #{cache_info1["count"]} but it wasnt: #{cache_info2}." if cache_info2["count"] >= cache_info1["count"]
|
163
164
|
|
164
165
|
|
166
|
+
#Test thread-safety and more.
|
167
|
+
ts = []
|
168
|
+
1.upto(25) do |tcount|
|
169
|
+
ts << Thread.new do
|
170
|
+
str = $php.func("substr", "Kasper Johansen", 0, 100)
|
171
|
+
|
172
|
+
0.upto(250) do
|
173
|
+
kasper_str = $php.func("substr", str, 0, 6)
|
174
|
+
johansen_str = $php.func("substr", str, 7, 15)
|
175
|
+
|
176
|
+
raise "Expected 'Kasper' but got '#{kasper_str}'." if kasper_str != "Kasper"
|
177
|
+
raise "Expected 'Johansen' but got '#{johansen_str}'." if johansen_str != "Johansen"
|
178
|
+
|
179
|
+
STDOUT.print "."
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
ts.each do |t|
|
185
|
+
t.join
|
186
|
+
end
|
187
|
+
|
188
|
+
|
165
189
|
#Destroy the object.
|
166
190
|
$php.destroy
|
167
191
|
end
|
metadata
CHANGED
@@ -1,105 +1,103 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: php_process
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.10
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Kasper Johansen
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2012-08-10 00:00:00 +02:00
|
12
|
+
date: 2012-10-17 00:00:00.000000000 +02:00
|
14
13
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
17
16
|
name: php-serialize4ruby
|
18
|
-
requirement: &
|
17
|
+
requirement: &15324340 !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
24
23
|
type: :runtime
|
25
24
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: *15324340
|
26
|
+
- !ruby/object:Gem::Dependency
|
28
27
|
name: wref
|
29
|
-
requirement: &
|
28
|
+
requirement: &15323460 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
35
34
|
type: :runtime
|
36
35
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: *15323460
|
37
|
+
- !ruby/object:Gem::Dependency
|
39
38
|
name: tsafe
|
40
|
-
requirement: &
|
39
|
+
requirement: &15322720 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
46
45
|
type: :runtime
|
47
46
|
prerelease: false
|
48
|
-
version_requirements: *
|
49
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
version_requirements: *15322720
|
48
|
+
- !ruby/object:Gem::Dependency
|
50
49
|
name: rspec
|
51
|
-
requirement: &
|
50
|
+
requirement: &15322080 !ruby/object:Gem::Requirement
|
52
51
|
none: false
|
53
|
-
requirements:
|
52
|
+
requirements:
|
54
53
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
54
|
+
- !ruby/object:Gem::Version
|
56
55
|
version: 2.8.0
|
57
56
|
type: :development
|
58
57
|
prerelease: false
|
59
|
-
version_requirements: *
|
60
|
-
- !ruby/object:Gem::Dependency
|
58
|
+
version_requirements: *15322080
|
59
|
+
- !ruby/object:Gem::Dependency
|
61
60
|
name: rdoc
|
62
|
-
requirement: &
|
61
|
+
requirement: &15321440 !ruby/object:Gem::Requirement
|
63
62
|
none: false
|
64
|
-
requirements:
|
63
|
+
requirements:
|
65
64
|
- - ~>
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3.12'
|
68
67
|
type: :development
|
69
68
|
prerelease: false
|
70
|
-
version_requirements: *
|
71
|
-
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: *15321440
|
70
|
+
- !ruby/object:Gem::Dependency
|
72
71
|
name: bundler
|
73
|
-
requirement: &
|
72
|
+
requirement: &15320700 !ruby/object:Gem::Requirement
|
74
73
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
78
77
|
version: 1.0.0
|
79
78
|
type: :development
|
80
79
|
prerelease: false
|
81
|
-
version_requirements: *
|
82
|
-
- !ruby/object:Gem::Dependency
|
80
|
+
version_requirements: *15320700
|
81
|
+
- !ruby/object:Gem::Dependency
|
83
82
|
name: jeweler
|
84
|
-
requirement: &
|
83
|
+
requirement: &15320000 !ruby/object:Gem::Requirement
|
85
84
|
none: false
|
86
|
-
requirements:
|
85
|
+
requirements:
|
87
86
|
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
87
|
+
- !ruby/object:Gem::Version
|
89
88
|
version: 1.8.3
|
90
89
|
type: :development
|
91
90
|
prerelease: false
|
92
|
-
version_requirements: *
|
93
|
-
description: Spawns a PHP process and proxies calls to it, making it possible to proxy
|
91
|
+
version_requirements: *15320000
|
92
|
+
description: Spawns a PHP process and proxies calls to it, making it possible to proxy
|
93
|
+
objects and more.
|
94
94
|
email: k@spernj.org
|
95
95
|
executables: []
|
96
|
-
|
97
96
|
extensions: []
|
98
|
-
|
99
|
-
extra_rdoc_files:
|
97
|
+
extra_rdoc_files:
|
100
98
|
- LICENSE.txt
|
101
99
|
- README.rdoc
|
102
|
-
files:
|
100
|
+
files:
|
103
101
|
- .document
|
104
102
|
- .rspec
|
105
103
|
- Gemfile
|
@@ -115,34 +113,31 @@ files:
|
|
115
113
|
- spec/spec_helper.rb
|
116
114
|
has_rdoc: true
|
117
115
|
homepage: http://github.com/kaspernj/php_process
|
118
|
-
licenses:
|
116
|
+
licenses:
|
119
117
|
- MIT
|
120
118
|
post_install_message:
|
121
119
|
rdoc_options: []
|
122
|
-
|
123
|
-
require_paths:
|
120
|
+
require_paths:
|
124
121
|
- lib
|
125
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
123
|
none: false
|
127
|
-
requirements:
|
128
|
-
- -
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
|
131
|
-
segments:
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
segments:
|
132
129
|
- 0
|
133
|
-
|
134
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
hash: -3803288112951647499
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
132
|
none: false
|
136
|
-
requirements:
|
137
|
-
- -
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version:
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
140
137
|
requirements: []
|
141
|
-
|
142
138
|
rubyforge_project:
|
143
139
|
rubygems_version: 1.6.2
|
144
140
|
signing_key:
|
145
141
|
specification_version: 3
|
146
142
|
summary: Ruby-to-PHP bridge
|
147
143
|
test_files: []
|
148
|
-
|